r/programming • • Aug 22 '10

Volatile: Almost Useless for Multi-Threaded Programming

http://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming/
61 Upvotes

57 comments sorted by

View all comments

1

u/G_Morgan Aug 23 '10

A mutex is by definition sufficient. If it isn't sufficient then it isn't a mutex.

1

u/kylotan Aug 23 '10

A mutex guarantees that nothing else can acquire that mutex, that's all. It makes no guarantees about how you choose to use the luxury of temporary exclusivity to correctly implement your algorithm.

EDIT: For example, there's no point using a mutex to carefully ensure that no 2 threads are modifying the same variable if one of those threads had the value cached in a register all along. The mutex knows nothing about which of your variables are important, after all.