Optimization of conditional access to globals: thread-unsafe?
Darryl Miles
darryl-mailinglists@netbauds.net
Mon Oct 29 15:16:00 GMT 2007
Michael Matz wrote:
> if (condition)
> *p = value;
>
> (i.e. without any synchronization primitive or in fact anything else after
> the store in the control region) and expect that the store indeed only
> happens in that control region. And this expectation is misguided. Had
> they written it like:
>
> if (condition) {
> *p = value;
> membarrier();
> }
>
> it would have worked just fine.
Don't you need the barrier before. This is to ensure it completed the
condition test completely first before it then processed the assignment
expression.
if(condition) {
somebarrier();
*p = value;
}
The issue is not that the store is done too late, but that a
write-access is done too early.
Darryl
More information about the Gcc
mailing list