boost-thread

Resetting sleeping time of a thread

自作多情 提交于 2021-01-27 07:42:42
问题 Suppose to have a thread like this void mythread() { int res; while(1) { { boost::lock_guard<boost::mutex> lock(mylock); res = do_my_stuff(); } boost::this_thread::sleep(boost::posix_time::seconds(5)); } } and that the thread is currently sleeping. If something happens outside of the thread, I'd like to be able to increase the sleep time. What is the best way to do it? 回答1: Using a condition_variable to signal changes to the deadline This has the benefit of supporting scenarios where the

How to make Boost dylibs universal (i386 & x86_64) on os x?

爱⌒轻易说出口 提交于 2020-12-09 04:17:08
问题 I'm trying to compile a Boost library into a universal binary file (i.e. a "fat" file that contains builds for both the i386 and x86_64 architectures). Souring the internet and SO I assembled the following instructions. Download boost (e.g. from http://www.boost.org/users/download/) In the downloaded folder, type ./bootstrap.sh (or, in my case ./bootstrap.sh --with-libraries=thread , since I only need the thread library) type ./b2 install cxxflags="-arch i386 -arch x86" These steps installed

How to make Boost dylibs universal (i386 & x86_64) on os x?

只谈情不闲聊 提交于 2020-12-09 04:16:48
问题 I'm trying to compile a Boost library into a universal binary file (i.e. a "fat" file that contains builds for both the i386 and x86_64 architectures). Souring the internet and SO I assembled the following instructions. Download boost (e.g. from http://www.boost.org/users/download/) In the downloaded folder, type ./bootstrap.sh (or, in my case ./bootstrap.sh --with-libraries=thread , since I only need the thread library) type ./b2 install cxxflags="-arch i386 -arch x86" These steps installed

asio use_future instead of yield[ec]

随声附和 提交于 2020-05-13 14:35:19
问题 i want to make container of futures ,each future is void result of a task so that i could use wait_for_any on the container ,each task is coroutine which i currently implement using yield_context,and inside this coroutine there initiating function which returns ec and result where i use ec to analyze result.and then another coroutine is called passes same yield_context . i want to know how to make this design. and if i ll use use_future ,how can i pass error code to ec not throwing it unless

Debug boost::thread application, high false positive rate

纵然是瞬间 提交于 2020-01-29 13:14:45
问题 I have programmed a boost::thread application, where I might have some race conditions. I want to debug this program. Therefore I used the following valgrind tools: halgrind drd unfortunately they have a very false positive rate. So with the really simple program below valgrind --tool=drd complains about 94 errors, where no should be. So with my complex program I get about 15000 errors. So it is really hard to find the actual error. I could reproduce this behavior with the following boost

Visual Studio 2015 c++/CLI boost::thread [duplicate]

眉间皱痕 提交于 2020-01-23 12:28:24
问题 This question already has an answer here : How do I create a C++/CLI Winforms app in VS2012? (1 answer) Closed 3 years ago . This issue has been around for all Visual Studio versions, but in VS 2015 the "old tricks" don't seem to work anymore. This is what I have tried: create a Windows Forms application in VS 2013 and 2015 (the macro is missing since VS 2013, so see this post: Can't find Windows Forms Application for C++) add boost headers path to Additional Include Directories add #include

C++ - How do I revive a thread with boost?

落爺英雄遲暮 提交于 2020-01-17 07:54:48
问题 SUMMARY: Client is in Teamspeak server with other users. When other users begin speaking, this plugin runs a function setSpeakerPosition() on the user every 500ms until they stop speaking. It should do it again if they start speaking again. PROBLEM: If I simply do a .reset(new boost::thread(...)) every time they start speaking, it seems to overwrite an existing thread (if they've spoken before) and leads to a crash. I believe I need to 'revive' an existing thread, or kill it properly. //

Kill Boost thread with another timeout thread

风格不统一 提交于 2020-01-16 02:02:24
问题 I want to end a thread WorkerThread after a certain amount of time has elapsed. I was thinking to use a second thread TimeoutThread for this, that changes a flag after 15 seconds so the other thread stops. Is there a more elegant way in boost to do this? #include <boost/thread.hpp> struct MyClass { boost::thread timeoutThread; boost::thread workerThread; bool btimeout = true; void run() { timeoutThread = boost::thread(boost::bind(&MyClass::TimeoutThread, this)); workerThread = boost::thread

Boost.Thread wakes up too late in 1.58

让人想犯罪 __ 提交于 2020-01-13 09:55:36
问题 I have an application that needs to do work within certain windows (in this case, the windows are all 30 seconds apart). When the time is not within a window, the time until the middle of the next window is calculated, and the thread sleeps for that amount of time (in milliseconds, using boost::this_thread::sleep_for ). Using Boost 1.55, I was able to hit the windows within my tolerance (+/-100ms) with extreme reliability. Upon migration to Boost 1.58, I am never able to hit these windows.

Can mutex implementations be interchanged (independently of the thread implementation)

天大地大妈咪最大 提交于 2020-01-13 09:43:33
问题 Do all mutex implementations ultimately call the same basic system/hardware calls - meaning that they can be interchanged? Specifically, if I'm using __gnu_parallel algorithms (that uses openmp ) and I want to make the classes they call threadsafe may I use boost::mutex for the locking? or must I write my own mutex such as the one described here //An openmp mutex. Can this be replaced with boost::mutex? class Mutex { public: Mutex() { omp_init_lock(&_mutex); } ~Mutex() { omp_destroy_lock(&