Questions tagged [boost-thread]

Boost.Thread enables the use of multiple threads of execution with shared data in portable C++ code.

Boost.Thread enables the use of multiple threads of execution with shared data in portable C++ code. It provides classes and functions for managing the threads themselves, along with others for synchronizing data between the threads or providing separate copies of data specific to individual threads.

The Boost.Thread library was originally written and designed by William E. Kempf. For Boost 1.35+, Anthony Williams performed a major rewrite designed to closely follow the proposals presented to the C++ Standards Committee, in particular N2497, N2320, N2184, N2139, and N2094.

As of Boost version 1.50.0 Boost.Thread provides an almost complete implementation of the C++ 2011 Threads library, plus extensions such as shared locks and thread interruption.

885 questions
21
votes
3 answers

How to pass an argument to boost::thread?

thread_ = boost::thread( boost::function< void (void)>( boost::bind( &clientTCP::run , this ) ) ); is it possible that run has an argument like this : void clientTCP::run(boost:function func); and if yes how my boost::thread…
Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
20
votes
4 answers

Multiple mutex locking strategies and why libraries don't use address comparison

There is a widely known way of locking multiple locks, which relies on choosing fixed linear ordering and aquiring locks according to this ordering. That was proposed, for example, in the answer for "Acquire a lock on two mutexes and avoid…
Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79
20
votes
9 answers

Kill a blocked Boost::Thread

I am writing an application which blocks on input from two istreams. Reading from either istream is a synchronous (blocking) call, so, I decided to create two Boost::threads to do the reading. Either one of these threads can get to the "end" (based…
mmocny
  • 8,775
  • 7
  • 40
  • 50
18
votes
1 answer

Boost Thread - How to acknowledge interrupt

I have blocking task which will be performed by find_the_question() function. However, I do not want thread executing this function take more than 10 seconds. So in case it takes more than 10 seconds, I want to close that thread with cleaning all…
Amey Jah
  • 913
  • 3
  • 11
  • 24
18
votes
1 answer

Usage example of boost::condition::timed_wait

Does someone have an example of how to most easily use boost::condition::timed_wait? There are some threads on the topic here, here and here, but none feature a working example. And boost doc is as usual quite sparse.
Cookie
  • 12,004
  • 13
  • 54
  • 83
18
votes
4 answers

What’s the best way to delete boost::thread object right after its work is complete?

I create boost::thread object with a new operator and continue without waiting this thread to finish its work: void do_work() { // perform some i/o work } boost::thread *thread = new boost::thread(&do_work); I guess, it’s necessary to delete…
itsvetkov
  • 616
  • 1
  • 6
  • 9
17
votes
2 answers

Creating a thread pool using boost

Is it possible to create a thread pool using boost's thread? i was looking all over boost's libs and I couldn't find a thread pool manager (or something like that)... Is there a way to do it? tnx!
grich
  • 463
  • 3
  • 6
  • 14
17
votes
3 answers

Give a name to a boost thread?

Is it possible to give a name to a boost::thread so that the debuggers tables and the crash logs can be more readable? How?
moala
  • 5,094
  • 9
  • 45
  • 66
17
votes
6 answers

On which platforms is thread local storage limited and how much is available?

I was recently made aware that thread local storage is limited on some platforms. For example, the docs for the C++ library boost::thread read: "Note: There is an implementation specific limit to the number of thread specific storage objects that…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
16
votes
1 answer

false sharing in boost::detail::spinlock_pool?

I came across this SO question and reading it over eventually led me to look at boost::detail::spinlock_pool. The purpose of boost::detail::spinlock_pool is to reduce potential contention for a global spinlock by choosing from an array of spinlocks…
mcmcc
  • 822
  • 6
  • 12
15
votes
5 answers

BOOST: recursive shared_mutex?

Seems that Boost's shared_mutex is non recursive.. Is there anyway around this? (without re implementing the whole stuff)
GabiMe
  • 18,105
  • 28
  • 76
  • 113
15
votes
2 answers

Trouble using boost/thread headers with clang++ (Windows)

I'm trying to use Boost.Thread on Windows using clang++. While including boost/thread.hpp, I'm getting the following compile errors: Using -DBOOST_USE_WINDOWS_H: In file included from D:/env/boost/boost_1_58_0\boost/thread.hpp:13: In file included…
saarraz1
  • 2,999
  • 6
  • 29
  • 44
14
votes
3 answers

How can I return a scoped lock?

Consider, say, a collection of account balances. And then you have a complex function that needs to check the balances of a few different accounts and then adjust the balances of a few different accounts. The operations need to be atomic with…
David Schwartz
  • 179,497
  • 17
  • 214
  • 278
14
votes
10 answers

Can multithreading speed up memory allocation?

I'm working with an 8 core processor, and am using Boost threads to run a large program. Logically, the program can be split into groups, where each group is run by a thread. Inside each group, some classes invoke the 'new' operator a total of 10000…
Nav
  • 19,885
  • 27
  • 92
  • 135
14
votes
4 answers

Why does this calculation give different result in boost::thread and std::thread?

When this floating point calculation is executed in boost::thread, it gives different result than when executed in std::thread or in main thread. void print_number() { double a = 5.66; double b = 0.0000001; double c = 500.4444; …
VLL
  • 9,634
  • 1
  • 29
  • 54
1
2
3
58 59