I'm trying for the first time create a MT application and I need some help.
If I use std::mutex to lock the object and another thread will try to access it, what will happen?
Lets say I have following:
In thread1:
Code: Select all
int foo()
{
std::lock_guard<std::mutex>( my_mutex );
// some operations
return true;
}
Code: Select all
int bar()
{
std::lock_guard<std::mutex>( my_mutex );
// some operations
return true;
}
What happen?
If the second thread is trying to acquire the lock in and if it can't will it keep trying until successful? Or the "keep trying" portion is on me?
Or maybe there is a better way of doing it?
Thank you.