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
9
votes
1 answer

When using boost::thread::interrupt(), do you *need* to catch the thread_interrupted exception?

I've got several long running boost threads that I want to be able to shut down by interrupting them. All of the documentation I can find says that you can catch the thread_interrupted exception, but it doesn't really say what happens if you…
Rob W.
  • 362
  • 5
  • 18
9
votes
1 answer

Why is destructor of boost::thread detaching joinable thread instead of calling terminate() as standard suggests?

According to the draft C++0x standard, this code: void simplethread() { boost::thread t(someLongRunningFunction); // Commented out detach - terminate() expected. // t.detach(); } ... should result in an terminate() call, but in…
mhl666
  • 874
  • 8
  • 15
9
votes
3 answers

Designing a thread-safe copyable class

The straightforward way to make a class threadsafe is to add a mutex attribute and lock the mutex in the accessor methods class cMyClass { boost::mutex myMutex; cSomeClass A; public: cSomeClass getA() { boost::mutex::scoped_lock lock(…
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
9
votes
4 answers

Does Multiple reader single writer implementation in g++-4.4(Not in C++11/14) via boost::shared_mutex impact performance?

Usage: In our production we have around 100 thread which can access the cache we are trying to implement. If cache is missed then information will be fetched from the database and cache will be updated via writer thread. To achieve this we are…
Ajay yadav
  • 4,141
  • 4
  • 31
  • 40
9
votes
3 answers

How can I achieve something similar to a semaphore using boost in c++?

I noticed that boost does not seem to support semaphores. What's the easiest way to achieve a similar effect?
jonderry
  • 23,013
  • 32
  • 104
  • 171
9
votes
2 answers

Does boost::asio::deadline_timer use a thread for each timer?

I have a list of items that I need to update on different intervals. The list can grow to be thousands of items long. Each item could potentially have a different interval. If I create one timer per item, am I going to saturate the system with…
Rhubarb
  • 3,893
  • 6
  • 41
  • 55
9
votes
1 answer

boost::asio with boost::unique_future

According to http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/overview/cpp2011/futures.html, we can use boost::asio with std::future. But I couldn't find any information about working with boost::unique_future, which has more functions, such…
ikh
  • 10,119
  • 1
  • 31
  • 70
9
votes
1 answer

Static Compile of Thread Example

I compiled the Boost C++ libraries as follows: bjam install variant=release link=static threading=multi runtime-link=static No errors. Then I compiled the following source: #include #include #define…
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
9
votes
2 answers

boost::thread - Simple example doesn't work (C++)

To get started with boost::thread, I've written a very simple example -- which doesn't work. Could anyone point out my mistake? I wrote a very simple functor-type class to do the work. It's supposed to compute the sum of an std::vector of doubles,…
user1889797
  • 143
  • 1
  • 7
9
votes
4 answers

Trying to link Boost 1.52 thread

I am trying to compile my program but it wouldn't link at all. I have specified the path to the boost lib files and the linker still complain. Here's the linking error I got: 1>Edproj.obj : error LNK2001: unresolved external symbol "class…
9
votes
1 answer

Am I over-engineering per-thread signal blocking?

In my applications, I generally want to intercept SIGINT and SIGTERM signals in order to close down gracefully. In order to prevent worker threads from "stealing" signals, I do this in the entrypoint for each: // Block signals in this…
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
9
votes
1 answer

Do we need multiple io_service per thread for threaded boost::asio server with a single acceptor

I am not much experienced in boost::asio. I've some pretty basic questions. Do I need to have a different io_service, and a different socket under a different thread but one single acceptor, to process a client in a threaded server ? I believe I…
Dipro Sen
  • 4,350
  • 13
  • 37
  • 50
9
votes
4 answers

Can I create a software watchdog timer thread in C++ using Boost Signals2 and Threads?

I am running function Foo from somebody else's library in a single-threaded application currently. Most of the time, I make a call to Foo and it's really quick, some times, I make a call to Foo and it takes forever. I am not a patient man, if Foo…
Aron Ahmadia
  • 2,267
  • 2
  • 19
  • 22
9
votes
3 answers

Shared Queue in C++

I just simply get packets from network, and Enqueue them in one thread and then consume this packets (Dequeue) in an other thread. So i decide to use boost library to make a shared queue based…
Novalis
  • 2,265
  • 6
  • 39
  • 63
8
votes
2 answers

C++/Cli : Could not load file or assembly X or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

I have a C++ project, a C++\Cli project and a c# win forms project. When i access the cli project from win forms project, i can access and use cli project functions. But when i include my cpp project headers into cli project, i get this run time…
Seçkin Durgay
  • 2,758
  • 4
  • 27
  • 36