Should I make my MutexLock volatile?

Posted by sje397 on Stack Overflow See other posts from Stack Overflow or by sje397
Published on 2011-11-24T09:46:58Z Indexed on 2011/11/24 9:50 UTC
Read the original article Hit count: 190

Filed under:
|
|
|

I have some code in a function that goes something like this:

void foo() {
    { // scope the locker
      MutexLocker locker(&mutex);
      // do some stuff..
    }
    bar();
}

The function call bar() also locks the mutex.

I am having an issue whereby the program crashes (for someone else, who has not as yet provided a stack trace or more details) unless the mutex lock inside bar is disabled.

Is it possible that some optimization is messing around with the way I have scoped the locker instance, and if so, would making it volatile fix it? Is that a bad idea?

Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about multithreading