Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why cannot the compiler optimization issues just be side-stepped by declaring the relevant shared variables volatile?

0
Posted

Why cannot the compiler optimization issues just be side-stepped by declaring the relevant shared variables volatile?

0

This turns out to be impractical, for several reasons: • The examples of compiler-introduced data races in the previously cited PLDI paper deal mostly with cases in which a shared variable, say x is already protected by a lock. Hence we would have to require the programmer to declare lock-protected variables, i.e. internal monitor variables, volatile. This was clearly never the intention of the pthread standard. (See the discussion of Memory Synchronization in SUSV3.) More importantly, this turns out to be completely impractical. It is very common to “wrap” single-threaded code in a lock to make it usable in a multithreaded application. This would not be possible if all variables/fields in the single-threaded code now had to be declared volatile. Thread-safe versions of the C++ standard library, effectively rely on this approach, which we believe to be the only viable one. It is also similar to the one adopted by more recent Java container libraries, for example. Requiring volatile dec

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123