This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: threadsafeness at egcs1.0.3 and 1.1
- To: egcs at cygnus dot com
- Subject: Re: threadsafeness at egcs1.0.3 and 1.1
- From: Ulrich Drepper <drepper at cygnus dot com>
- Date: 10 Jul 1998 20:24:11 -0700
- Newsgroups: cygnus.egcs
- Organization: Cygnus Solutions
- References: <2353046752.900001211@DUCAT.INI.CMU.EDU>, <199807102001.WAA01324.cygnus.egcs@mira.isdn.cs.tu-berlin.de>
- Reply-To: drepper at cygnus dot com (Ulrich Drepper)
martin@mira.isdn.cs.tu-berlin.de (Martin von Loewis) writes:
> int f()
> {
> static int i = get_some_value();
> return i;
> }
>
> If two threads call f concurrently, initialization might be performed
> twice. Since this can be handled on the application level in many
> cases, it is not considered a serious problem (by some).
This is a case for calling pthread_once which is associated with a
quite high cost (the pthread_once_t is normally at least two words
long). Plus there is the problem of handling this case if no threaded
program is used. (Note that it isn't possible to have a simple "not
done"/"done" flag since the second thread arriving must not return from
the get_some_value call until the first did and this requires
interaction with the thread package. Busy waiting is no option since
the waiting thread might have a higher priority.)
I see this case as a real boundary case which probably shouldn't
handled at all and the use of non-const initializing of static
variables should be outlawed.
--
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com `------------------------