3
votes

Say we are on linux (C++) and using some threading library to launch threads and I do not know what library it is. Now I need to use mutex. Can I just use the mutex from somewhere (for example, boost::thread, std::thread, tbb), or I have to use the mutex class provided by the same library which launched the threads?

I understand that it is best to use the mutex from the same library. But just curious...Especially, what if we assume all these libraries under discussion uses pthread as underlying threading library?

1
I would recommend to stay with one library. Either boost or std. Mixing them up doesnt make any sense at all. - Sebastian Hoffmann
Stick to one library. Whether it is boost, stl, or something else is preference mostly ... - AJG85

1 Answers

3
votes

You don't actually need to in the sense that you could do it and the world won't end. However, the library launching the thread might assume something that the one that gives you the mutex doesn't provide, and things will certainly go wrong there.

I doubt that a threading library provides the thread abstraction and not the mutex one, so use only one library. There's no real need of mixing things up.