This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimization of conditional access to globals: thread-unsafe?


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]