Nếu tôi hiểu cách trình biên dịch C++ xử lý các biến cục bộ thì IsShutdownInProgress()
không cần bất kỳ khóa nào vì biến tĩnh tĩnh shutdownInProgress
sẽ được đặt trên ngăn xếp. Tôi có đúng không?Mutex khi trả về giá trị đối tượng
class MyClass
{
private:
// Irrelevant code commented away
static pthread_mutex_t mutex;
static bool shutdownInProgress;
public:
static void ShutdownIsInProgress()
{
pthread_mutex_lock(mutex);
shutdownInProgress = true;
pthread_mutex_unlock(mutex);
}
static bool IsShutdownInProgress()
{
// pthread_mutex_lock(mutex);
// pthread_mutex_unlock(mutex);
return shutdownInProgress;
}
}