Is it safe to use std::mutex
and its kin in a program that starts its threads via boost?
(Using std::thread
is not an option for me (I think), as the application needs a lot of stack space, and on some platforms requires overriding the default stack size upon creation.)
Shared mutexes and locks are an optimization for read-only pieces of multi-threaded code. It is totally safe for multiple threads to read the same variable, but std::mutex can not be locked by multiple threads simultaneously, even if those threads only want to read a value.
Mutex is an abbreviation for mutual exclusion, as in, a mutex allows only one thread to access some data at any given time.
In C++, we create a mutex by constructing an instance of std::mutex, lock it with a call to the member function lock(), and unlock it with a call to the member function unlock().
Boost. Sync supports building against one of the following underlying APIs: pthreads or Windows API. On most platforms pthreads are the only option. On Windows, Windows API is used by default, but pthreads can be enabled.
Yes, you can use std::mutex
in threads created with boost::thread
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With