This is the mail archive of the
mailing list for the GCC project.
Re: Optimization of conditional access to globals: thread-unsafe?
- From: Ian Lance Taylor <iant at google dot com>
- To: "Bart Van Assche" <bart dot vanassche at gmail dot com>
- Cc: "Tomash Brechko" <tomash dot brechko at gmail dot com>, gcc at gcc dot gnu dot org, "Andrew Pinski" <pinskia at gmail dot com>
- Date: 26 Oct 2007 08:20:05 -0700
- Subject: Re: Optimization of conditional access to globals: thread-unsafe?
- References: <firstname.lastname@example.org> <email@example.com>
"Bart Van Assche" <firstname.lastname@example.org> writes:
> * As known the compiler may reorder function calls and assignments
> to non-volatile variables if the compiler can prove that the called
> function won't modify that variable. This becomes problematic if the
> variable is modified by more than one thread and the called function
> is a synchronization function, e.g. pthread_mutex_lock(). This kind of
> reordering is highly undesirable. This is why any variable that is
> shared over threads has to be declared volatile, even when using
> explicit locking calls.
What happens in practice is that pthread_mutex_lock and friends are
magic functions. In gcc, this magic implemented using inline