What's the use of volatile in Wine code?
robertshearman at gmail.com
Wed Nov 11 17:09:16 CST 2009
2009/11/11 <Joerg-Cyril.Hoehle at t-systems.com>:
> AJ wrote in http://www.winehq.org/pipermail/wine-devel/2009-November/079575.html
>>If there is proper synchronization you don't need
>>volatile, and if there isn't volatile won't magically fix it.
> However, mcimidi has in its code since pre 1999:
> :/* it seems that in case of multi-threading, gcc is optimizing just a little bit
> : * too much. Tell gcc not to optimize status value using volatile.
> : */
> :while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
> The comment is right. Any C compiler is allowed to optimize this into
> an endless loop without volatile. But I'd rather see the following:
> :volatile dwStatus = NOT_READY; /* one central declaration */
> :while (wmm->dwStatus == PAUSE) ; /* what, busy wait!?! */
> So what's the use of volatile? When is it appropriate in Wine?
I haven't looked in detail at the context of your patch, but this
looks appropriate to it:
Particularly the part about volatile storage vs. access.
More information about the wine-devel