This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: threadsafeness at egcs1.0.3 and 1.1


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   `------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]