简体   繁体   English

线程安全问题

[英]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. 我有一个疑问,当我从ClassA:funcA()调用ClassA:funcB() -其中ClassA:funcA()监视器,而当我调用ClassA:funcB()它位于监视器内部。

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? ClassA:funcB()正从只调用funcA()它是线程安全的?

Sure. 当然。 If funcB is only called from funcA while funcA has acquired the mutex, then you are thread safe. 如果funcB 仅仅从所谓的funcA同时funcA收购互斥,那么你是线程安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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