I was asked a question about mutex before, the code works fine, but I am confused about this result:
::std::mutex s_mutex;
void funcA()
{
s_mutex.lock();
printf( "funcA \n" );
s_mutex.unlock();
}
void funcB()
{
s_mutex.lock();
funcA();
printf( "funcB \n" );
s_mutex.unlock();
}
int main()
{
funcB();
return 0;
}
It works fine and print what I did not etxpect:
funcA
funcB
But why? This func is called in main thread and seems to call lock twice.
Aucun commentaire:
Enregistrer un commentaire