This is the mail archive of the
mailing list for the GCC project.
Re: Optimization of conditional access to globals: thread-unsafe?
On Mon, Oct 29, 2007 at 01:08:22 -0700, Andrew Pinski wrote:
> On 10/29/07, Tomash Brechko <firstname.lastname@example.org> wrote:
> > But if *v is simply shared, do all stores to it matter? No, only the
> > final value is relevant.
> Actually it depends, it might matter. If you have a loop checking the
> value of *v on a different thread and it does not change until this
> loop is done, then you end up with a wrong wait. This is the same as
> what violatile is for really where it will change out side of the
> current thread.
Such program would be incorrect wrt POSIX Threads: you shouldn't read
the object that may be modified by another thread. Such "wait" loop
is always wrong wrt POSIX Threads.