|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-02-11 07:21:54
Ben Hutchings wrote:
> Paul wrote:
>>
>>> Synchronous cancellation may be simulated by setting a simple flag
>>> polled by the cancellable thread. (Appropriate memory barriers must
>>> be placed after setting and before polling the flag. In the absence
>>> of portable memory barrier facilities, one may protect the flag
>>> with a mutex, though that's annoyingly heavyweight.) However this
>>> does not
>>
>>
>> just out of curiousity, why do you think you need a memory barrier
>> on a flag? you would have 1 writer and 1 reader... either the
>> reader reads false or true, and once the writer has set it to
>> true... thats it, the reader will read true on the next pass.
>
> In practice, if you use "volatile" then the compiler will probably
> generate code to read the flag from memory every time and the reader
> will probably see the change, possibly after some small delay for it
> to work its way through the write queue on the processor that the
> writer is running on. AFAIK no standard or specification guarantees
> this.
If the cache of the reader CPU isn't notified about the change (which is
only guaranteed to happen on an acquire) the reader may never observe the
modified value.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net