This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Sequenced-Before for g++ 4.1.2?
- From: Hei Chan <structurechart at yahoo dot com>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 12 Apr 2012 23:55:05 -0700 (PDT)
- Subject: Sequenced-Before for g++ 4.1.2?
- Reply-to: Hei Chan <structurechart at yahoo dot com>
Hi,
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"
An concrete example:
class B {};
class A {
public:
?? std::map<long, B*> m_myMap;
?? A::A() {
?????? m_myMap[0] = new B();
?????? pthread_t threadID;
?????? pthread_create(&threadID, NULL, start, NULL);
?? }
?? static void* start(void*) {
?????? // use m_myMap[0] here, will this new thread sees everything happens before it gets created (e.g. m_myMap[0] contains the valid value)?
?? }
}
Thanks in advance.
Cheers,
Hei