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?


On Mon, Oct 29, 2007 at 01:08:22 -0700, Andrew Pinski wrote:
> On 10/29/07, Tomash Brechko <tomash.brechko@gmail.com> 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.


-- 
   Tomash Brechko


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