Boost logo

Boost Users :

From: Paul (elegant_dice_at_[hidden])
Date: 2005-02-10 19:46:32


> 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.

even if the reader is reading the same time as the writer is writing,
and byte-sized memory writes are not atomic (which i think they are),
then the read will still evaluate to true, which is what is desired anyway.

so theres no need for a mutex in this case? even if there were
multiple writers, its a one-way flag set operation, all would be trying
to set the flag to true if all were writing at the same time, so all
would get the desired result?

thanks
Paul


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