int main() { { boost::unique_lock<boost::mutex> lk(mut); boost::thread t(f); BOOST_TEST(test1 == 0); while (test1 == 0) cv.wait(lk); BOOST_TEST(test1 != 0); test2 = 1; lk.unlock(); cv.notify_one(); t.join(); } test1 = 0; test2 = 0; { boost::unique_lock<boost::mutex> lk(mut); boost::thread t(f); BOOST_TEST(test1 == 0); while (test1 == 0) cv.wait(lk); BOOST_TEST(test1 != 0); lk.unlock(); t.join(); } return boost::report_errors(); }
virtual ~NetworkCacheLayer() { cleanup = true; // Prevents doFetch (callback for NameLookup) from starting a new download. std::list<DownloadHandler::TransferDataPtr> pendingDelete; { boost::unique_lock<boost::mutex> transfer_lock(mActiveTransferLock); for (std::list<RequestInfo>::iterator iter = mActiveTransfers.begin(); iter != mActiveTransfers.end(); ++iter) { if ((*iter).httpreq) { pendingDelete.push_back((*iter).httpreq); } } } std::list<DownloadHandler::TransferDataPtr>::iterator iter; for (iter = pendingDelete.begin(); iter != pendingDelete.end(); ++iter) { (*iter)->abort(); } { boost::unique_lock<boost::mutex> transfer_lock(mActiveTransferLock); while (!mActiveTransfers.empty()) { mCleanupCV.wait(transfer_lock); } } }
void wait() { boost::unique_lock<boost::mutex> lock ( mutex_ ); while ( count_ == 0 ) { condition_.wait ( lock ); } --count_; }
int main( int argc, char* argv[] ) { TA_Base_Test::CBoostLogger BoostLogger; BOOST_LOG_FUNCTION(); TA_Base_Test::CTestCase* pTestCase = new TA_Base_Test::CTestCase(); if (1 == g_runAsServer) { pTestCase->runTestCase_ForServer(); } else { pTestCase->runTestCase_ForClient(); } // //sleep { boost::mutex::scoped_lock lock(g_mutexMainRun); g_conditionMainRun.wait(lock); } delete pTestCase; pTestCase = NULL; return 0; }
void wait() { boost::mutex::scoped_lock lock(mutex_); while(!count_) condition_.wait(lock); --count_; }
void WorkManagerImpl::WaitForWork() { boost::unique_lock<boost::mutex> lock(m_dispatchermutex); while(m_workreq <= 0) m_condition.wait(lock); m_workreq--; if(m_workreq < 0) m_workreq = 0; }
TaskPtr pull() { boost::unique_lock<boost::mutex> lock(_mutex); while (_running) { std::cout << "pull 0" << std::endl; if (!_tasks.empty()) { std::cout << "pull A" << std::endl; TaskPtr task = _tasks.front(); _tasks.pop_front(); return task; } else { std::cout << "pull B" << std::endl; _no_task.wait(lock); std::cout << "pull C" << std::endl; } } while (!_running) { std::cout << "pull 1" << std::endl; if (!_tasks.empty()) { std::cout << "pull D" << std::endl; TaskPtr task = _tasks.front(); _tasks.pop_front(); return task; } else { std::cout << "pull E" << std::endl; return TaskPtr(); } } return TaskPtr(); }
boost::shared_ptr< const MapsBuffer::MapsRgb > MapsBuffer::getFront(bool print) { boost::shared_ptr< const MapsBuffer::MapsRgb > depth_rgb; { boost::mutex::scoped_lock buff_lock (bmutex_); while (buffer_.empty ()) { if (is_done) break; { boost::mutex::scoped_lock io_lock (io_mutex); //std::cout << "No data in buffer_ yet or buffer is empty." << std::endl; } buff_empty_.wait (buff_lock); } depth_rgb = buffer_.front (); buffer_.pop_front (); } if(print) PCL_INFO("%d maps left in the buffer...\n", buffer_.size ()); return (depth_rgb); }
void displayThreadLoop() { printf("started image display thread!\n"); boost::unique_lock<boost::mutex> lock(openCVdisplayMutex); while(imageThreadKeepRunning) { openCVdisplaySignal.wait(lock); if(!imageThreadKeepRunning) break; while(displayQueue.size() > 0) { if(!displayQueue.back().autoSize) { if(openWindows.find(displayQueue.back().name) == openWindows.end()) { cv::namedWindow(displayQueue.back().name, cv::WINDOW_NORMAL); cv::resizeWindow(displayQueue.back().name, displayQueue.back().img.cols, displayQueue.back().img.rows); openWindows.insert(displayQueue.back().name); } } cv::imshow(displayQueue.back().name, displayQueue.back().img); cv::waitKey(1); displayQueue.pop_back(); } } cv::destroyAllWindows(); openWindows.clear(); printf("ended image display thread!\n"); }
void consumeToLog() { while (true) { try { typename LogObject::SmartPtr logObj; { boost::mutex::scoped_lock lock(_qMutex); while (_queue.size() == 0) { if (_isStopping) { std::cout << " Stopping consumeToLog Thread. " << std::endl; return; } _qCondVar.wait(lock); } // Get the entry logObj = _queue.front(); _queue.pop(); } printLogObject(logObj); } catch (const boost::thread_interrupted& err) { std::cout << " Log::consumeToLog() - Got Interrupt Signal. " << _queue.size() << std::endl; } }//while }
void record_thread_loop(void) { int buffer_no = 0; /* open log file*/ FILE *logfile = fopen("fwrite_thread_testlog.log","w"); BOOST_REQUIRE_MESSAGE(logfile != NULL, "Could not open logfile!"); boost::unique_lock<boost::mutex> lock(mutex); while(record_thread_running) { record_trigger.wait(lock); if(buffer_no < 2) { active_buffer = &string_buffer_2; fwrite(string_buffer_1.c_str(), sizeof(char), string_buffer_1.length(), logfile); string_buffer_1.clear(); buffer_no = 2; } else { active_buffer = &string_buffer_1; fwrite(string_buffer_2.c_str(), sizeof(char), string_buffer_2.length(), logfile); string_buffer_2.clear(); buffer_no = 1; } } fclose(logfile); }
void slave_thread(int id) { printf(" +++ slave thread %d: starting\n", id); while (true) { boost::unique_lock<boost::mutex> lock(data_ready_mutex); while (!data_ready) { data_ready_cond.wait(lock); } data_ready = false; unsigned work_unit; { boost::lock_guard<boost::mutex> lock(work_queue_mutex); if (work_queue.size() == 0) abort(); work_unit = work_queue.back(); work_queue.pop_back(); } printf(" slave thread %d: got work unit %u\n", id, work_unit); // Pretend to work boost::chrono::milliseconds sleepDuration(3); boost::this_thread::sleep_for(sleepDuration); } printf(" --- slave thread %d: finished\n", id); }
static void status_paused_wait(Recog *recog, void *dummy) { boost::unique_lock<boost::mutex> lock(pause_mutex); pause_variable.wait(lock); }
void record_thread_loop(void) { int buffer_no = 0; std::ofstream logfile; /* open log file*/ logfile.open ("stream_thread_testlog.log", ios::out); if (!logfile.is_open()) { cout << "Could not open logfile!" << endl; } boost::unique_lock<boost::mutex> lock(mutex); while(datagen_thread_running) { record_trigger.wait(lock); if(buffer_no < 2) { active_buffer = &string_buffer_2; logfile << string_buffer_1; string_buffer_1.clear(); buffer_no = 2; } else { active_buffer = &string_buffer_1; logfile << string_buffer_2; string_buffer_2.clear(); buffer_no = 1; } } logfile.close(); }
int main(int argc, char* argv[]) { if (argc < 3) { cout << "Usage: " << argv[0] << " <host> <port> [magic_bytes=0xd9b4bef9ul]" << endl << " Pings a bitcoin-like node and gets the version information." << endl; return 0; } uint16_t port = strtoul(argv[2], NULL, 10); NetworkAddress address(NODE_NETWORK, DEFAULT_Ipv6, port); CoinNodeSocket nodeSocket; try { nodeSocket.open(MessageHandler, listener_network::MAGIC_BYTES, listener_network::PROTOCOL_VERSION, argv[1], port); nodeSocket.doHandshake(listener_network::PROTOCOL_VERSION, NODE_NETWORK, time(NULL), address, address, 0, "", 0); nodeSocket.waitOnHandshakeComplete(); boost::unique_lock<boost::mutex> lock(mutex); while (!bGotVersion) gotVersion.wait(lock); } catch (const exception& e) { cout << e.what() << endl; } }
bool PresentationEngineManager::startDocument( const std::string &file ) { LDEBUG( "PresentationEngineManager", "Start document: doc=%s", file.c_str() ); if (formatter()) { _sys->enqueue( boost::bind( &PresentationEngineManager::stopDocument, this ) ); { // Wait for compare boost::unique_lock<boost::mutex> lock( _stopMutex ); while (!_stopped) { _stopWakeup.wait( lock ); } _stopped = false; } } // Init settings module player::settings::init(); initFormatter( file ); if (!formatter()->parseDocument()) { LWARN( "PresentationEngineManager", "parseDocument fail" ); return false; } // Play formatter _sys->enqueue( boost::bind( &FormatterMediator::play, formatter() ) ); return true; }
void pop(T &result) { boost::unique_lock<boost::mutex> u(m); c.wait(u, [&]{return !q.empty();} ); result = move_if_noexcept(q.front()); q.pop(); }
void operator()() { boost::unique_lock<boost::mutex> lk(mut); while(!done) { cond.wait(lk); } }
void wait() { boost::unique_lock<boost::mutex> l(m); while(!flag) { cond.wait(l); } }
void operator()() { boost::mutex::scoped_lock lk(mut); while(!done) { cond.wait(lk); } }
void wait_and_pop ( Data& value ) { boost::mutex::scoped_lock lock ( _mutex ) ; while ( _queue.empty () ) _cond.wait ( lock ) ; value = _queue.front () ; _queue.pop () ; }
void wait() { boost::mutex::scoped_lock l(m); while(!flag) { cond.wait(l); } }
unsigned long long waitAndGetFrontElement(T* &pFrontData) { boost::mutex::scoped_lock lock(_mutex); while (_queue.empty()) { _conditionVar.wait(lock); } pFrontData = _queue.front().data; return _queue.front().pushedTime; }
void wait_with_predicate() { boost::unique_lock<boost::mutex> lock(mutex); cond_var.wait(lock,check_flag(flag)); if(flag) { ++woken; } }
void wait_for_data_to_process() { boost::unique_lock<boost::mutex> unique_lock(mutex); while(!data_ready) { condition_variable.wait(unique_lock); } process_data(); }
void operator()() { boost::unique_lock<boost::mutex> lock(mutex_); while (!terminated_) { io_service_.run(); condition_.wait(lock); } }
void wait_without_predicate() { boost::unique_lock<boost::mutex> lock(mutex); while(!flag) { cond_var.wait(lock); } ++woken; }
int wait(int* old_val = NULL) { if (old_val && *old_val != m_count) { *old_val = m_count; return 0; } scoped_lock g(m_lock); try { m_cond.wait(g); } catch(...) { return -1; } return 0; }
// for data queue void wait_and_push(T data) { boost::mutex::scoped_lock lockHandle(mutexHandle); condFlag.wait(lockHandle, isFull(&queueHandle, sizeMax)); queueHandle.push(data); lockHandle.unlock(); condFlag.notify_all(); }
int main(int argc, char* argv[]) { StringVec args = StringVec(argv, argv + argc); if(argc > 1 && !argumentsHandler(args)) return 0; std::set_new_handler(allocationHandler); ServiceManager servicer; g_config.startup(); #ifdef __OTSERV_ALLOCATOR_STATS__ boost::thread(boost::bind(&allocatorStatsThread, (void*)NULL)); // TODO: shutdown this thread? #endif #ifdef __EXCEPTION_TRACER__ ExceptionHandler mainExceptionHandler; mainExceptionHandler.InstallHandler(); #endif #ifndef WINDOWS // ignore sigpipe... struct sigaction sigh; sigh.sa_handler = SIG_IGN; sigh.sa_flags = 0; sigemptyset(&sigh.sa_mask); sigaction(SIGPIPE, &sigh, NULL); // register signals signal(SIGHUP, signalHandler); //save signal(SIGTRAP, signalHandler); //clean signal(SIGCHLD, signalHandler); //refresh signal(SIGUSR1, signalHandler); //close server signal(SIGUSR2, signalHandler); //open server signal(SIGCONT, signalHandler); //reload all signal(SIGQUIT, signalHandler); //save & shutdown signal(SIGTERM, signalHandler); //shutdown #endif OutputHandler::getInstance(); Dispatcher::getInstance().addTask(createTask(boost::bind(otserv, args, &servicer))); g_loaderSignal.wait(g_loaderUniqueLock); if(servicer.isRunning()) { std::clog << ">> " << g_config.getString(ConfigManager::SERVER_NAME) << " server Online!" << std::endl << std::endl; servicer.run(); } else std::clog << ">> " << g_config.getString(ConfigManager::SERVER_NAME) << " server Offline! No services available..." << std::endl << std::endl; #ifdef __EXCEPTION_TRACER__ mainExceptionHandler.RemoveHandler(); #endif return 0; }