Bug 56220 - g++ failed to initialize a __thread local bool variable.
Summary: g++ failed to initialize a __thread local bool variable.
Status: RESOLVED MOVED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.3
: P3 major
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-06 08:49 UTC by gccbug
Modified: 2013-02-06 09:02 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gccbug 2013-02-06 08:49:54 UTC
c++ front end failed to initialize a "__thread" local "bool" variable with value "true" in a multi-threaded environment. I also did more tests, it could initialize the variable to "false" correctly. Also it could initialize an "int" variable correctly.

The bug would also be reproduced with both driver "gcc" and "g++":

witch@desktop:/tmp$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

witch@desktop:/tmp$ cat t.cpp
#include <stdio.h>
#include <pthread.h>

void g(bool x) {
	printf("%d\n", x);
}

void* f(void* arg) {
	static __thread bool i = true;
	g(i);
	return NULL;
}

int main() {
	pthread_t a, b;
	pthread_create(&a, NULL, &f, NULL);
	pthread_create(&b, NULL, &f, NULL);
	pthread_join(a, NULL);
	pthread_join(b, NULL);
	return 0;
}
witch@desktop:/tmp$ g++ t.cpp -O2 -pthread
witch@desktop:/tmp$ ./a.out 
1
1
witch@desktop:/tmp$ g++ t.cpp -O0 -pthread
witch@desktop:/tmp$ ./a.out 
0
0
Comment 1 Andreas Schwab 2013-02-06 09:02:27 UTC
This is glibc bug 14898 <http://sourceware.org/bugzilla/show_bug.cgi?id=14898>, fixed in glibc 2.17.