Question

When working with multithreading, I need to make sure that the boost classes I use are reentrant (even when each thread uses its own object instance).

I'm having hard time finding in the documentation of Boost's classes a statement about the reentrancy of the class. Am I missing something here? Are all the classes of Boost reentrant unless explicitly stated otherwise in the documentation? Or is Boost's documentation on reentrancy a gray area?

For example, I couldn't find anywhere in the documentation a statement on the reentrancy of the boost::numeric::ublas∷matrix class. So can I assume it's reentrant or not?

Thanks!

Ofer

Was it helpful?

Solution

Most of Boost is similar to most of the STL and the C++ standard library in that:

  • Creating two instances of a type in two threads at the same time is OK.
  • Using two instances of a type in two threads at the same time is OK.
  • Using a single object in two threads at the same time is often not OK.
  • But doing read-only operations on one object in two threads is often OK.
  • There is usually no particular effort taken to "enhance" thread safety, except where there is a particular need to do so, like shared_ptr, Asio, Signals2 (but not Signals), and so on. Parts of Boost that look like value types (such as your matrix example) probably do not have any special thread safety support at all, leaving it up to the application.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top