简体   繁体   中英

Thread safe issues

I have got doubt, when I call ClassA:funcB() from ClassA:funcA() - where ClassA:funcA() HAS monitor and when I call ClassA:funcB() it's inside monitor.

Here:

static pthread_mutex_t my_mutex;

ClassA::funcA()
{
    monitor mp(my_mutex);
    err = funcB();
}

ClassA::funcB()
{
  ...
  stuff with NO lock etc
  ...
}

ClassA:funcB() is getting called from ONLY funcA() , is it thread safe?

Sure. If funcB is only called from funcA while funcA has acquired the mutex, then you are thread safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM