If the documentation does not address it, We could suggest that is unspecified and if it is not specified, you may have some surprise gessing that they obtain the lock in the same order they ask...
In order to be sure that the threads obtain the mutex in the same order they ask, I suggest you to take a look at std::condition_variable
or at std::condition_variable_any
.
They are both declared in <condition_variable>
library header. In both cases, they need to work with a mutex in order to provide appropriate synchronization.
Here is a little example of how you can use it :
#include <mutex>
#include <condition_variable>
std::mutex mut;
std::queue<dummyData> data;
std::condition_variable cond;
void dummyDataPrepare()
{
while( more_data_in_preparation() )
{
std::lock_guard<std::mutex> lo( mut );
// doing many things on data
cond.notify_one();
}
}
void dummyDataProcessingThread()
{
while( true )
{
std::unique_lock<std::mutex> lo( mut );
cond.wait( lo,
[]{ return !data.empty(); });
// Do whatever you want ...
lo.unlock();
}
}
This example shows how you can wait for some data to process before doing something on it.