boost-thread

What does boost::condition_variable::timed_wait() return on spurious wakeups?

不羁的心 提交于 2019-12-13 17:06:32
问题 The boost documentation says: Returns: false if the call is returning because the time specified by abs_time was reached, true otherwise. But what is returned if there is a spurious wakeup? 回答1: If the condition variable could figure that it is a spurious wake-up there would be no need to return, would it? You need to check if the data protected by the mutex and the condition variable has changed to detect a spurious wake-up. The condition variable can not do that for you. 来源: https:/

C++ boost::thread and automatically locking containers

我们两清 提交于 2019-12-13 15:08:14
问题 Is there a way to automatically lock an STL container on access, without having to lock and release around it? 回答1: The currrent C++ standard does not say anything about thread safety for STL containers. Officially it is possible for an STL implementation to be thread safe, but it's very unusual. If your STL implementation is not thread safe, then you will need to "lock and release around it" or find some other way to coordinate access. You may be interested in Intel's Threading Building

increasing efficiency of following code using threads

99封情书 提交于 2019-12-13 08:16:51
问题 I'm using a machine having 8 cores and 32GB ram. In this machine, I'm running a code in c++ using VS2010 on Windows x64 which takes 3 days to complete 8 trees(8 is the number of outer threads). I searched for bottleneck and find out that crossCorrelate method takes around 75-80% of the time. Now, I'm trying to make that method more efficient, code is as follows: int main(){ int numThread = 8; //create threads, run build_tree method for each of them //and join after running all of them } // I

How to make sure all slave threads are waited for conditional variable?

谁说我不能喝 提交于 2019-12-13 05:27:12
问题 I am running the following chunk of the code. This code is going to create 5 slave threads and 1 main thread. All slave threads are waited for the main thread to make the data ready and when the data gets ready, all slaves will notify to start processing. My question is, it is possible that before the slave threads start waiting for the conditional_variable , the main thread make the data ready and notify the waited threads. In this case, some threads which were waited will get the

Pattern for future conversion

主宰稳场 提交于 2019-12-13 05:19:52
问题 currently we are using asynchronous values very heavily. Assume that I have a function which does something like this: int do_something(const boost::posix_time::time_duration& sleep_time) { BOOST_MESSAGE("Sleeping a bit"); boost::this_thread::sleep(sleep_time); BOOST_MESSAGE("Finished taking a nap"); return 42; } At some point in code we create a task which creates a future to such an int value which will be set by a packaged_task - like this (worker_queue is a boost::asio::io_service in this

memory fences/barriers in C++: does boost or other libraries have them?

五迷三道 提交于 2019-12-12 21:22:23
问题 I am reading these days about memory fences and barriers as a way to synchronize multithreaded code and avoid code reordering. I usually develop in C++ under Linux OS and I use boost libs massively but I am not able to find any class related to it. Do you know if memory barrier of fences are present in boost or if there is a way to achieve the same concept? If not what good library can I have a look to? 回答1: There are no low-level memory barriers in boost yet, but there is a proposed boost

program.exe: Native' has exited with code 255 (0xff)

血红的双手。 提交于 2019-12-12 20:04:11
问题 I am using boost threads, and everything works perfectly when compiling with /MD but I really prefer compiling with /MT instead The problem I then get is program.exe: Native' has exited with code 255 (0xff). This happens on this line: thread_1 = thread(testThread,test); after digging down deeper, I realised the problem is the fact that _crtheap equals to 0, ie: it's not initialized. as seen in mlock.c /* * Check if CRT is initialized. The check if _crtheap is initialized * will do the job.

how to overcome building error when I'm using bcp to export boost thread?

↘锁芯ラ 提交于 2019-12-12 19:22:40
问题 I'm using boost bcp tool to export thread library from boost. The layout of exported library is - Jamroot + libs |----- + thread |----- + build |----- - Jamfile.v2 + boost + doc Now when I run bjam in build library is getting me : boostcpp.jam: No such file or directory ../../../Jamroot:138: in modules.load rule boostcpp.set-version unknown in module Jamfile</Users/miladrezayee/Softwares/developer/boost_1_53_0/tmp1> /Users/miladrezayee/Softwares/developer/boost_1_53_0/tools/build/v2/build

Boost condition variables - do calls to “notify_one” stack?

被刻印的时光 ゝ 提交于 2019-12-12 15:38:00
问题 In a single producer / single consumer application using Boost threads, what happens if the producer thread makes more than one call to cond_var.notify_one() before the consumer thread has called cond_var.wait(lock) ? Will the additional calls to notify_one be stacked, such that each call to .wait() will correspond 1:1 with a .notify_one() call? EDIT A commonly quoted example for implementing a concurrent queue has these methods: void push(Data const& data) { boost::mutex::scoped_lock lock

Why might this thread management pattern result in a deadlock?

旧城冷巷雨未停 提交于 2019-12-12 11:43:13
问题 I'm using a common base class has_threads to manage any type that should be allowed to instantiate a boost::thread . Instances of has_threads each own a set of thread s (to support waitAll and interruptAll functions, which I do not include below), and should automatically invoke removeThread when a thread terminates to maintain this set 's integrity. In my program, I have just one of these. Threads are created on an interval every 10s, and each performs a database lookup. When the lookup is