does presence of mutex help getting rid of volatile key word ?

前端 未结 5 1487
一个人的身影
一个人的身影 2020-12-09 20:57

I have a multi-R/W lock class that keeps the read, write and pending read , pending write counters. A mutex guards them from multiple threads.

My question is Do we

5条回答
  •  北海茫月
    2020-12-09 21:28

    While this may depend on the threading library you are using, my understanding is that any decent library will not require use of volatile.

    In Pthreads, for example, use of a mutex will ensure that your data gets committed to memory correctly.

    EDIT: I hereby endorse tony's answer as being better than my own.

提交回复
热议问题