More on memory barriers

Richard Henderson rth@redhat.com
Wed Sep 15 08:45:00 GMT 2004


On Wed, Sep 15, 2004 at 02:22:03AM -0400, Jason Merrill wrote:
> if (!initialized)
>   {
>     acquire_lock();
>     if (!initialized)
>       {
>         initialize ();
>         memory_barrier(); // force serialization on all CPUs
>         initialized = true;
>       }
>     release_lock();
>   }
> 
> On Alpha we need a second memory barrier, i.e.
> 
> else
>   read_memory_barrier ();

Well, no, Alpha needs

  read_memory_barrier ();
  if (!initialized)
    {
      acquire_lock ();
      if (!initialized)
	{
	  initialize ();
	  write_memory_barrier ();
	  initialized = true;
	}
      release_lock ();
    }

> On ia64, does a release barrier have the desired semantics, or do we need a
> full barrier?

Release is sufficient.  In particular, the barriers that must be
present for the lock release are sufficient to ensure that the
read of initialized happens after the write.

We do still need a write_memory_barrier here.  For that,
__sync_synchronize is still the best implementation available.


r~



More information about the Gcc mailing list