Sequenced-Before for g++ 4.1.2?

Ian Lance Taylor iant@google.com
Sat Apr 14 05:46:00 GMT 2012


Hei Chan <structurechart@yahoo.com> writes:

> I am still on 4.1.2 (which defaults to use C98), and I wonder whether g++ 4.1.2 guarantees that everything happens before (e.g. write to a variable) will be reflected in another thread if:
> 1. there is no lock (e.g. pthread_mutex/spinlock) involving
> 2. the "another thread" is created (e.g. calling pthread_create) after the "write"

The relevant question for the compiler is whether it will issue all
writes to globally visible memory before calling pthread_create.  The
answer is: yes, it will.

The rest is up to your library.  I would expect that any pthread library
would have a memory barrier during pthread_create, in which case you
should be fine.

Ian



More information about the Gcc-help mailing list