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
151
votes
12 answers

C++0x has no semaphores? How to synchronize threads?

Is it true that C++0x will come without semaphores? There are already some questions on Stack Overflow regarding the use of semaphores. I use them (posix semaphores) all the time to let a thread wait for some event in another thread: void…
tauran
  • 7,986
  • 6
  • 41
  • 48
118
votes
6 answers

Example for boost shared_mutex (multiple reads/one write)?

I have a multithreaded app that has to read some data often, and occasionally that data is updated. Right now a mutex keeps access to that data safe, but it's expensive because I would like multiple threads to be able to read simultaneously, and…
kevin42
  • 2,108
  • 3
  • 22
  • 21
67
votes
3 answers

How to create a thread pool using boost in C++?

How do I create a thread pool using boost in C++, and how do I assign tasks to the threadpool?
Jeroen
  • 15,257
  • 12
  • 59
  • 102
43
votes
7 answers

C++ Thread Pool

What is a good open source implementation of a thread pool for C++ to use in production code (something like boost)? Please provide either your own example code or a link to example code usage.
Amir Rachum
  • 76,817
  • 74
  • 166
  • 248
40
votes
3 answers

why is string not declared in scope

I have the following code: #include #include static boost::thread_specific_ptr _tssThreadNameSptr; I get the following error g++ -c -I$BOOST_PATH tssNaming.h tssNaming.h:7: error: 'string' was not declared…
Jimm
  • 8,165
  • 16
  • 69
  • 118
37
votes
3 answers

shared_ptr Assertion px != 0 failed

I have a fairly complex multi threaded application (server) that from time to time will crash due to an assert: /usr/include/boost/smart_ptr/shared_ptr.hpp:418: T* boost::shared_ptr< >::operator->() const [with T =…
Horacio
  • 2,727
  • 5
  • 26
  • 29
33
votes
2 answers

Intel TBB vs Boost

I my new application I have flexibility to decide the use of library for multi-threading. So far I was using pthread. Now want to explore cross platform library. I zero in on TBB and Boost. I didn't understand what is the benefit of TBB over Boost.…
David
  • 4,634
  • 7
  • 35
  • 42
30
votes
2 answers

boost::thread_group in C++11?

Is there anything like boost::thread_group in C++11? I'm just trying to port my program from using boost:thread to C++11 threads and wasn't able to find anything equivalent.
AbuBakr
  • 968
  • 2
  • 11
  • 22
29
votes
3 answers

What's the difference between "mutex" and "lock"?

I am very confused about the difference between a lock and mutex. In Boost docs, it says, Lock Types Class template lock_guard Class template unique_lock Class template shared_lock Class template upgrade_lock Class template…
2607
  • 4,037
  • 13
  • 49
  • 64
26
votes
3 answers

How to use lock_guard when returning protected data

I have a question concerning the use of boost::lock_guard (or similar scoped locks) and using variables that should be protected by the lock in a return statement. How is the order of destroying local objects and copying the return value? How does…
Hannah S.
  • 3,081
  • 3
  • 20
  • 27
26
votes
7 answers

Boost thread error: undefined reference

#include #include void hello() { std::cout << "Hello world, I'm a thread!" << std::endl; } int main(int argc, char* argv[]) { boost::thread thrd(&hello); thrd.join(); return 0; } I ran tried to…
lal
  • 269
  • 1
  • 3
  • 3
26
votes
3 answers

C++ gettid() was not declared in this scope

A simple program is: I would like to get the thread ID of both of the threads using this gettid function. I do not want to do the sysCall directly. I want to use this function. #include #include #include…
Hiesenberg
  • 415
  • 1
  • 8
  • 12
25
votes
2 answers

Boost.Thread Linking - boost_thread vs. boost_thread-mt

It's not clear to me what linking options exist for the Boost.Thread 1.34.1 library. I'm on Ubuntu 8.04 and I've found that when using either boost_thread or boost_thread-mt during linking both compile and run, but I don't see any documentation on…
Robert S. Barnes
  • 39,711
  • 30
  • 131
  • 179
25
votes
4 answers

(simple) boost thread_group question

I'm trying to write a fairly simple threaded application, but am new to boost's thread library. A simple test program I'm working on is: #include #include int result = 0; boost::mutex result_mutex; boost::thread_group…
RandomGuy
  • 1,658
  • 4
  • 18
  • 21
24
votes
1 answer

boost::threadpool::pool vs.boost::thread_group

I'm trying to understand the different use cases. and the difference between the 2 thread uses. This is a great tutorial I have read which explains boost::thread_group. and here is a code I'm using: boost::threadpool::pool…
Gilad
  • 6,437
  • 14
  • 61
  • 119
1
2 3
58 59