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
14
votes
3 answers

Synchronizing access to a return value

Consider the following C++ member function: size_t size() const { boost::lock_guard lock(m_mutex); return m_size; } The intent here is not to synchronize access to the private member variable m_size, but just to make sure…
Channel72
  • 143
  • 4
14
votes
4 answers

is std::queue thread safe with producer and multiple consumers

how can I make a queue thread safe? I need to push / pop / front / back and clear. is there something similar in boost? I have one producer and one or more consumer.
unikat
  • 341
  • 2
  • 5
  • 14
13
votes
4 answers

Program structure for bi-directional TCP communication using Boost::Asio

First off, I hope my question makes sense and is even possible! From what I've read about TCP sockets and Boost::ASIO, I think it should be. What I'm trying to do is to set up two machines and have a working bi-directional read/write link over TCP…
aardvarkk
  • 14,955
  • 7
  • 67
  • 96
13
votes
2 answers

Is it expected that use of boost::thread_specific_ptr<>::get() be slow? Any work arounds?

I'm currently profiling an application with performance problems using Valgrind's "Callgrind". In looking at the profiling data, it appears that a good 25% of processing time is being spent inside of boost::detail::get_tss_data in an application…
Catskul
  • 17,916
  • 15
  • 84
  • 113
13
votes
2 answers

thread destructors in C++0x vs boost

These days I am reading the pdf Designing MT programs . It explains that the user MUST explicitly call detach() on an object of class std::thread in C++0x before that object gets out of scope. If you don't call it std::terminate() will be called and…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
13
votes
4 answers

How to make boost::thread_group execute a fixed number of parallel threads

This is the code to create a thread_group and execute all threads in parallel: boost::thread_group group; for (int i = 0; i < 15; ++i) group.create_thread(aFunctionToExecute); group.join_all(); This code will execute all threads at once. What I…
user179476
13
votes
2 answers

Why does Valgrind show increasing stack usage with boost::thread?

Wrote a simple test: #include #include using namespace std; void myThreadRun() { cout << "Thread id: " << boost::this_thread::get_id() << "\n"; } int main() { for (int i = 0; i < 10000; i++) { …
weekens
  • 8,064
  • 6
  • 45
  • 62
12
votes
3 answers

How can I immediately cancel a curl operation?

I'm using libcurl in C++, and I'm calling curl_easy_perform in a separate thread from my UI using Boost.Thread. The main UI has a cancel button that I'd like to be perfectly responsive (i.e., when a user clicks on it, it should immediately react). I…
Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
12
votes
2 answers

What does boost::thread sleep() do?

I am currently working on a small wrapper class for boost thread but I dont really get how the sleep function works, this is what I have got so far: BaseThread::BaseThread(){ thread = boost::thread(); bIsActive =…
user240137
  • 693
  • 4
  • 10
  • 15
12
votes
2 answers

Parallel tasks get better performances with boost::thread than with ppl or OpenMP

I have a C++ program which could be parallelized. I'm using Visual Studio 2010, 32bit compilation. In short the structure of the program is the following #define num_iterations 64 //some number struct result { //some stuff } result…
888
  • 3,246
  • 8
  • 41
  • 60
12
votes
5 answers

Creating a boost::thread with boost::bind() or without

Some people seem to launch boost::threads using the boost::bind() function, like in the accepted answer of the following question: Using boost thread and a non-static class function Whereas other people don't use it at all, like in the answer with…
deinocheirus
  • 1,833
  • 5
  • 26
  • 44
11
votes
1 answer

Valgrind reports 'possibly lost' memory when working with Boost threads

I have a program that runs some action in a separate therad, then joins on the thread, such as this one: #include #include using namespace std; void f() { for (int i = 0; i < 100; ++i) cout << i << endl; } int…
petersohn
  • 11,292
  • 13
  • 61
  • 98
11
votes
4 answers

boost asio asynchronously waiting on a condition variable

Is it possible to perform an asynchronous wait (read : non-blocking) on a conditional variable in boost::asio ? if it isn't directly supported any hints on implementing it would be appreciated. I could implement a timer and fire a wakeup even every…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
11
votes
3 answers

Valgrind errors with boost::thread_specific_ptr on GCC 8.3 + Linux

Ubuntu 19 running inside Docker GCC 8.3 Boost 1.69 Valgrind 3.14.0 When the application is shutting down Valgrind reports these 3 issues: ==70== Mismatched free() / delete / delete [] ==70== at 0x483997B: free (in…
Robert Fraser
  • 10,649
  • 8
  • 69
  • 93
11
votes
2 answers

How to use boost::bind with non-copyable params, for example boost::promise?

Some C++ objects have no copy constructor, but have move constructor. For example, boost::promise. How can I bind those objects using their move constructors ? #include void fullfil_1(boost::promise& prom, int x) { …
user222202
  • 523
  • 4
  • 14
1 2
3
58 59