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
4
votes
0 answers

Why does boost::when_all spawn a new thread

I have the following code, compiled with Boost 1.62. #define BOOST_THREAD_VERSION 4 #define BOOST_THREAD_PROVIDES_EXECUTORS #include #include #include #include…
sbabbi
  • 11,070
  • 2
  • 29
  • 57
4
votes
0 answers

boost::barrier object lifetime — should it be kept alive after all threads reach wait()?

Consider the following: #include boost::thread spawn() { boost::barrier barrier{2}; boost::thread ret{[&barrier] { // some initialization code barrier.wait(); // actual thread code }}; …
Michał W. Urbańczyk
  • 1,453
  • 1
  • 12
  • 20
4
votes
2 answers

How to use boost::thread mutex to synchronize write access?

I have a newbie question about Boost::Thread and Mutex. I would like to start many parallel instances of the following Worker, and all of them write to the same std::vector: struct Worker { std::vector* vec; Worker(std::vector*…
Frank
  • 651
  • 1
  • 7
  • 9
4
votes
0 answers

What is the difference between poll and run?

Does anyone have an example illustrating the difference between boost::asio::io_service::poll and boost::asio::io_service::run? More specifically what is the difference between calling join_all() on a thread_group executing run() and on another one…
FlashMcQueen
  • 635
  • 3
  • 13
4
votes
1 answer

boost::shared_future and when_all with multiple continuations

I've got a DAG of tasks that I'm trying to execute using the boost::shared_future framework. For example concreteness, consider the data flow graph shown in the figure. Here's an attempt to code this up: #include #define…
Chris Dyer
  • 43
  • 5
4
votes
1 answer

boost::thread and creating a pool of them!

boost::thread class has a default constructor which gives a "Not-a-thread", so what is boost::thread t1; good for? Can I give it a function to execute later in the code? and another question: I'm trying to write a little server which has a staged…
p00ya00
  • 796
  • 1
  • 10
  • 20
4
votes
3 answers

Multithreading using the boost library

Wish to simultaneously call a function multiple times. I wish to use threads to call a function which will utilize the machines capability to the fullest. This is a 8 core machine, and my requirement is to use the machine cpu from 10% to 100% or…
gagneet
  • 35,729
  • 29
  • 78
  • 113
4
votes
1 answer

boost::threads - how to do graceful shutdown?

I'm trying to improve the portability of a C++ app by using boost:threads instead of our own wrapper over Win32 threads, and the issue of graceful thread termination (again) rears its ugly head. On pure win32, I 'interrupt' threads by using…
Roddy
  • 66,617
  • 42
  • 165
  • 277
4
votes
2 answers

Boost Spirit crash when used in DLLs

I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my application. This only happens if I have used the Spirit parser during the lifetime of the process from the main thread. The crash happens at exit and appears…
Morten Fjeldstad
  • 903
  • 2
  • 10
  • 16
4
votes
1 answer

How do I make the boost/asio library repeat a timer?

Here is the Code given on the Boost library documentation. #include #include #include void print(const boost::system::error_code& /*e*/) { std::cout << "Hello,…
Hiesenberg
  • 415
  • 1
  • 8
  • 12
4
votes
2 answers

Error while excuting a simple boost thread program

Could you tell mw what is the problem with the below boost::thread program #include #include boost::mutex mutex; class A { public: A() : a(0) {} void operator()() { boost::mutex::scoped_lock…
Eternal Learner
  • 3,800
  • 13
  • 48
  • 78
4
votes
3 answers

boost::thread application, strange data race reporting

I have programmed a boost::thread application, where I might have some race conditions based on valgrind/helgrind report. I want to identify the reason of these races. The program is: #include boost::mutex…
radekg1000
  • 71
  • 7
4
votes
1 answer

Type of boost::future<> from boost::async()

I am getting unexpected results from boost::async() (Boost 1.56, Windows: VS2010 and VS2012). #include ... auto func = [](){ return 123; }; auto boostFut = boost::async(func); // boostFut = 42; // intentional error to…
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
4
votes
1 answer

What is wrong with the mutexes in this attempt at a `std::future` implementation for C++03?

I'm trying to adapt Martinho Fernandes's sample std::future implementation so that it can run under C++03 with Boost 1.40, as a cheap, stop-gap measure until I can gain access to either Boost 1.41 or C++11 itself. My adaption is hardly beautiful and…
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
4
votes
2 answers

Resetting sleeping time of a thread

Suppose to have a thread like this void mythread() { int res; while(1) { { boost::lock_guard lock(mylock); res = do_my_stuff(); } boost::this_thread::sleep(boost::posix_time::seconds(5)); } } and that…
Bob
  • 10,741
  • 27
  • 89
  • 143