Bug 1830 - thread local storage: static class member does not work
Summary: thread local storage: static class member does not work
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-08 10:58 UTC by Simon Marshall
Modified: 2016-05-17 18:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
code to demonstrate bug (1.44 KB, application/x-compressed)
2005-11-08 11:00 UTC, Simon Marshall
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Marshall 2005-11-08 10:58:22 UTC
The attached code (assuming I manage to attach it) shows that there is a problem
with thread-local storage when used from a library and a static class member. 
The attached code creates 10 threads.  Each thread uses 3 different mechanisms
to store the thread's identity in thread-local storage: (1) in a global
thread-local variable, (2) in a static member of a class, (3) in a static member
of an instantiated template class.  Each thread prints out its values for each
of these after thread start and before thread end.  You should see each thread
reporting the same value for each storage mechanism (and different values for
the thread-local storage addresses).  This is what happens on our Solaris and
Windows platforms.   
 
However, this does not happen on RedHat, because for mechanisms (2) and (3),
each mechanism shares the data across the threads (the threads do not have their
own location).  As a result, typically the "thread…ends" output for each thread
contains the correct value and unique address for mechanism (1), but for (2) and
(3) the values and addresses are of one (or two) of the threads.
 
It appears (see GCC bugzilla #13668) that this bug is due to glibc.  I've seen
this problem on RHEL3 and RHEL4.  My RHEL4 is using 3.4.4 20050721 (Red Hat
3.4.4-2), though I've tried it with a locally built 4.0.2 also.  Sorry, I don't
know how to tell the version of libc, it's out-of-the-box.

To see the problem, unpack the attached tgz and "make && ./a.out".  You will see
the first (and second) column correctly showing unique thread ids (and addresses
where the values are stored), but the other columns will not.
Comment 1 Simon Marshall 2005-11-08 11:00:01 UTC
Created attachment 750 [details]
code to demonstrate bug
Comment 2 Tom Gall 2005-11-08 21:43:57 UTC
looking into this one
Comment 3 Jakub Jelinek 2005-11-08 21:45:37 UTC
No need, it is a GCC bug I have just committed fix for.