/** * 根据统计信息调整当前线程的本地分配缓冲区的基准大小 */ void ThreadLocalAllocBuffer::resize() { if (ResizeTLAB) { //允许调整线程的本地分配缓冲区大小 // Compute the next tlab size using expected allocation amount size_t alloc = (size_t)(_allocation_fraction.average() * (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize)); size_t new_size = alloc / _target_refills; //根据本地分配缓冲区大小允许的最大值/最小值来调整缓冲区的新大小 new_size = MIN2(MAX2(new_size, min_size()), max_size()); //内存对齐后的大小 size_t aligned_new_size = align_object_size(new_size); if (PrintTLAB && Verbose) { gclog_or_tty->print("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]" " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT "\n", myThread(), myThread()->osthread()->thread_id(), _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size); } set_desired_size(aligned_new_size); set_refill_waste_limit(initial_refill_waste_limit()); } }
int main() { boost::asio::io_service ioService; boost::asio::io_service::work work(ioService); std::thread myThread( [&ioService]() { std::cout << "io_service thread id: " << std::this_thread::get_id() << std::endl; ioService.run(); }); ip::tcp::resolver::query query("127.0.0.1", "12345"); ip::tcp::resolver resolver(ioService); ip::tcp::resolver::iterator iterator = resolver.resolve(query); ip::tcp::socket socket(ioService); boost::asio::async_connect(socket, iterator, [](const boost::system::error_code& error, ip::tcp::resolver::iterator iterator) { if (!error) { ip::tcp::endpoint endpoint(*iterator); std::cout << "Made a connection to: " << endpoint; std::cout << " on thread id: "; std::cout << std::this_thread::get_id() << std::endl; } }); myThread.join(); return 0; }
int main(int argc, char ** argv) { std::cout << "Trying to create new thread..." << std::endl; boost::thread myThread(threadFunc); myThread.join(); std::cout << "New thread finished job" << std::endl; return 0; }
/** * 计算当前线程的本地分配缓冲区的新大小 */ inline size_t ThreadLocalAllocBuffer::compute_size(size_t obj_size) { const size_t aligned_obj_size = align_object_size(obj_size); // Compute the size for the new TLAB. // The "last" tlab may be smaller to reduce fragmentation. // unsafe_max_tlab_alloc is just a hint. const size_t available_size = Universe::heap()->unsafe_max_tlab_alloc(myThread()) / HeapWordSize; size_t new_tlab_size = MIN2(available_size, desired_size() + aligned_obj_size); // Make sure there's enough room for object and filler int[]. const size_t obj_plus_filler_size = aligned_obj_size + alignment_reserve(); if (new_tlab_size < obj_plus_filler_size) { // If there isn't enough room for the allocation, return failure. if (PrintTLAB && Verbose) { gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" " returns failure", obj_size); } return 0; } if (PrintTLAB && Verbose) { gclog_or_tty->print_cr("ThreadLocalAllocBuffer::compute_size(" SIZE_FORMAT ")" " returns " SIZE_FORMAT, obj_size, new_tlab_size); } return new_tlab_size; }
TEST(QiSession, CallOnCloseSession) { qi::Session sd; qi::Future<void> f = sd.listenStandalone("tcp://0.0.0.0:0"); int timeToWait = 1; for(int j = 0; j < 10 ; j ++) { for (int i = 0; i < 20; i++) { TestSessionPair p; std::cout << "time to wait is:" << timeToWait << std::endl; qi::SessionPtr s1 = p.server(); qi::SessionPtr s2 = p.client(); qi::DynamicObjectBuilder ob; ob.advertiseMethod("reply", &reply); qi::AnyObject obj(ob.object()); s1->registerService("service1", obj); qi::AnyObject myService; myService = s2->service("service1"); boost::thread myThread(boost::bind(&myCall, myService)); qi::os::msleep(timeToWait); s1->close(); qi::os::msleep(3); } timeToWait = timeToWait +1; } }
int main() { GOOGLE_PROTOBUF_VERIFY_VERSION; boost::asio::io_service ioService; boost::asio::io_service::work work(ioService); std::thread myThread( [&ioService]() { std::cout << "io_service thread id: "; std::cout << std::this_thread::get_id() << std::endl; ioService.run(); }); // // Only allowed to have one acceptor listening on a port at at time. // Therefore, creating it one time here and passing it into the handleNewConnection function. std::shared_ptr<ip::tcp::acceptor> acceptor = std::make_shared<ip::tcp::acceptor>(ioService, ip::tcp::endpoint(ip::tcp::v4(), 12345)); handleNewConnection(ioService, acceptor); myThread.join(); return 0; }
void ThreadLocalAllocBuffer::resize() { // Compute the next tlab size using expected allocation amount assert(ResizeTLAB, "Should not call this otherwise"); size_t alloc = (size_t)(_allocation_fraction.average() * (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize)); size_t new_size = alloc / _target_refills; new_size = MIN2(MAX2(new_size, min_size()), max_size()); size_t aligned_new_size = align_object_size(new_size); if (PrintTLAB && Verbose) { gclog_or_tty->print("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]" " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT "\n", p2i(myThread()), myThread()->osthread()->thread_id(), _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size); } set_desired_size(aligned_new_size); set_refill_waste_limit(initial_refill_waste_limit()); }
void ThreadLocalAllocBuffer::accumulate_statistics() { size_t capacity = Universe::heap()->tlab_capacity(myThread()) / HeapWordSize; size_t unused = Universe::heap()->unsafe_max_tlab_alloc(myThread()) / HeapWordSize; size_t used = capacity - unused; // Update allocation history if a reasonable amount of eden was allocated. bool update_allocation_history = used > 0.5 * capacity; _gc_waste += (unsigned)remaining(); if (PrintTLAB && (_number_of_refills > 0 || Verbose)) { print_stats("gc"); } if (_number_of_refills > 0) { if (update_allocation_history) { // Average the fraction of eden allocated in a tlab by this // thread for use in the next resize operation. // _gc_waste is not subtracted because it's included in // "used". size_t allocation = _number_of_refills * desired_size(); double alloc_frac = allocation / (double) used; _allocation_fraction.sample(alloc_frac); } global_stats()->update_allocating_threads(); global_stats()->update_number_of_refills(_number_of_refills); global_stats()->update_allocation(_number_of_refills * desired_size()); global_stats()->update_gc_waste(_gc_waste); global_stats()->update_slow_refill_waste(_slow_refill_waste); global_stats()->update_fast_refill_waste(_fast_refill_waste); } else { assert(_number_of_refills == 0 && _fast_refill_waste == 0 && _slow_refill_waste == 0 && _gc_waste == 0, "tlab stats == 0"); } global_stats()->update_slow_allocations(_slow_allocations); }
int main() { std::cout <<"entered main" << std::endl; boost::thread myThread(&thread_func); boost::thread::yield(); //myThread.join(); std::cout <<"main func ends" << std::endl; return 0; }
int main( ) { boost::thread myThread(threadFun); // Create a thread that starts // running threadFun boost::thread::yield( ); // Give up the main thread's timeslice // so the child thread can get some work // done. // Go do some other work... myThread.join( ); // The current (i.e., main) thread will wait // for myThread to finish before it returns }
size_t ThreadLocalAllocBuffer::initial_desired_size() { size_t init_sz = 0; if (TLABSize > 0) { init_sz = TLABSize / HeapWordSize; } else if (global_stats() != NULL) { // Initial size is a function of the average number of allocating threads. unsigned nof_threads = global_stats()->allocating_threads_avg(); init_sz = (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize) / (nof_threads * target_refills()); init_sz = align_object_size(init_sz); } init_sz = MIN2(MAX2(init_sz, min_size()), max_size()); return init_sz; }
int lua_main_manual(lua_State *L, const int& cb_ref, int ms) { juce::JUCEApplicationBase::createInstance = &juce_CreateApplication; MainThread myThread("Main luce Thread", L, cb_ref, ms); #if JUCE_IOS // not ready yet // luce_iOSMain(0, 0, &myThread); #else if (LUCEApplicationBase::run(myThread)) { lua_pushstring(L,"LUCE ERROR: Couldn't initialise app"); lua_error(L); return 0; } #endif return 0; }
void ThreadLocalAllocBuffer::accumulate_statistics() { Thread* thread = myThread(); size_t capacity = Universe::heap()->tlab_capacity(thread); size_t used = Universe::heap()->tlab_used(thread); _gc_waste += (unsigned)remaining(); size_t total_allocated = thread->allocated_bytes(); size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc; _allocated_before_last_gc = total_allocated; if (PrintTLAB && (_number_of_refills > 0 || Verbose)) { print_stats("gc"); } if (_number_of_refills > 0) { // Update allocation history if a reasonable amount of eden was allocated. bool update_allocation_history = used > 0.5 * capacity; if (update_allocation_history) { // Average the fraction of eden allocated in a tlab by this // thread for use in the next resize operation. // _gc_waste is not subtracted because it's included in // "used". // The result can be larger than 1.0 due to direct to old allocations. // These allocations should ideally not be counted but since it is not possible // to filter them out here we just cap the fraction to be at most 1.0. double alloc_frac = MIN2(1.0, (double) allocated_since_last_gc / used); _allocation_fraction.sample(alloc_frac); } global_stats()->update_allocating_threads(); global_stats()->update_number_of_refills(_number_of_refills); global_stats()->update_allocation(_number_of_refills * desired_size()); global_stats()->update_gc_waste(_gc_waste); global_stats()->update_slow_refill_waste(_slow_refill_waste); global_stats()->update_fast_refill_waste(_fast_refill_waste); } else { assert(_number_of_refills == 0 && _fast_refill_waste == 0 && _slow_refill_waste == 0 && _gc_waste == 0, "tlab stats == 0"); } global_stats()->update_slow_allocations(_slow_allocations); }
void ThreadLocalAllocBuffer::record_slow_allocation(size_t obj_size) { // Raise size required to bypass TLAB next time. Why? Else there's // a risk that a thread that repeatedly allocates objects of one // size will get stuck on this slow path. set_refill_waste_limit(refill_waste_limit() + refill_waste_limit_increment()); _slow_allocations++; if (PrintTLAB && Verbose) { Thread* thrd = myThread(); gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]" " obj: "SIZE_FORMAT " free: "SIZE_FORMAT " waste: "SIZE_FORMAT"\n", "slow", thrd, thrd->osthread()->thread_id(), obj_size, free(), refill_waste_limit()); } }
int main(int argc, char *argv[]) { object t2; InitDynace(&argc); /* Start the threader. This also makes the currently running main() function the first thread. */ StartThreader(argc); t2 = gNewThread(Thread, "t2", myThread, DEFAULT_PRIORITY, "t2", 1, 0); myThread("main"); gWaitFor(t2); return 0; }
void ThreadLocalAllocBuffer::initialize() { initialize(NULL, // start NULL, // top NULL); // end set_desired_size(initial_desired_size()); // Following check is needed because at startup the main (primordial) // thread is initialized before the heap is. The initialization for // this thread is redone in startup_initialization below. if (Universe::heap() != NULL) { size_t capacity = Universe::heap()->tlab_capacity(myThread()) / HeapWordSize; double alloc_frac = desired_size() * target_refills() / (double) capacity; _allocation_fraction.sample(alloc_frac); } set_refill_waste_limit(initial_refill_waste_limit()); initialize_statistics(); }
// Fills the current tlab with a dummy filler array to create // an illusion of a contiguous Eden and optionally retires the tlab. // Waste accounting should be done in caller as appropriate; see, // for example, clear_before_allocation(). void ThreadLocalAllocBuffer::make_parsable(bool retire) { if (end() != NULL) { invariants(); if (retire) { myThread()->incr_allocated_bytes(used_bytes()); } CollectedHeap::fill_with_object(top(), hard_end(), retire); if (retire || ZeroTLAB) { // "Reset" the TLAB set_start(NULL); set_top(NULL); set_pf_top(NULL); set_end(NULL); } } assert(!(retire || ZeroTLAB) || (start() == NULL && end() == NULL && top() == NULL), "TLAB must be reset"); }
Eigen::MatrixXd TwoDimensionalCut::getMatrix() { Eigen::MatrixXd mat(cut->getEnergies().size(), points.size()); progressBar pbar(points.size()); std::thread myThread(&progressBar::run, &pbar); #ifdef USE_THREADS tbb::parallel_for(tbb::blocked_range<std::size_t>(0, points.size()), [this, &pbar, &mat](const tbb::blocked_range<std::size_t> r) { std::unique_ptr<SpinWaveGenie::SpinWavePlot> cutclone = cut->clone(); for (std::size_t m = r.begin(); m < r.end(); ++m) { Eigen::MatrixXd::ColXpr values = mat.col(m); auto it = points.begin() + m; std::vector<double> val = cutclone->getCut((*it)[0], (*it)[1], (*it)[2]); #ifdef _MSC_VER std::copy(val.begin(), val.end(), stdext::make_checked_array_iterator(values.data(), values.size())); #else std::copy(val.begin(), val.end(), values.data()); #endif pbar.increment(); } }); #else for (std::size_t m = 0; m < points.size(); ++m) { Eigen::MatrixXd::ColXpr values = mat.col(m); auto it = points.begin() + m; std::vector<double> val = cut->getCut((*it)[0], (*it)[1], (*it)[2]); #ifdef _MSC_VER std::copy(val.begin(), val.end(), stdext::make_checked_array_iterator(values.data(), values.size())); #else std::copy(val.begin(), val.end(), values.data()); #endif pbar.increment(); } #endif myThread.join(); return mat; }
void ThreadLocalAllocBuffer::print_stats(const char* tag) { Thread* thrd = myThread(); size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste; size_t alloc = _number_of_refills * _desired_size; double waste_percent = alloc == 0 ? 0.0 : 100.0 * waste / alloc; size_t tlab_used = Universe::heap()->tlab_used(thrd); gclog_or_tty->print("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]" " desired_size: " SIZE_FORMAT "KB" " slow allocs: %d refill waste: " SIZE_FORMAT "B" " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB" " slow: %dB fast: %dB\n", tag, p2i(thrd), thrd->osthread()->thread_id(), _desired_size / (K / HeapWordSize), _slow_allocations, _refill_waste_limit * HeapWordSize, _allocation_fraction.average(), _allocation_fraction.average() * tlab_used / K, _number_of_refills, waste_percent, _gc_waste * HeapWordSize, _slow_refill_waste * HeapWordSize, _fast_refill_waste * HeapWordSize); }
void aiscript::determine_meld(GameTable* const gameStat) { THREADLIB::thread myThread(calcCall_threaded, gameStat); myThread.join(); }
DiscardTileNum aiscript::determine_discard(const GameTable* const gameStat) { DiscardTileNum discard = {DiscardTileNum::Normal, NumOfTilesInHand - 1}; THREADLIB::thread myThread(calcDiscard_threaded, std::ref(discard), gameStat); myThread.join(); return discard; }
int main() { std::thread myThread(); return 0; }