gcc / atexit() threading problem
Joe Buehler
jbuehler@hekimian.com
Thu Feb 13 14:51:00 GMT 2003
Back in July 2002 I reported a problem I was having with newlib in
Cygwin. Christopher Faylor forwarded my message to this list:
http://sources.redhat.com/ml/newlib/2002/msg00368.html
I would like to eliminate the patch I am currently using to
work around the problem. Here is some more information
for the newlib wizards -- perhaps there is an easy fix
for this that could be rolled into newlib.
The gcc compiler inserts calls to atexit() for static objects
declared inside functions, to schedule the destructor to be called
at program exit time. E.g.:
f()
{
// this results in a call to atexit() when the function enters
static some_class o;
}
This can cause problems in Cygwin binaries because atexit()
is not thread-safe. So what happens sometimes is that more than
one thread calls atexit() at the same time as part of a static
object constructor call, and the function pointer list used by
atexit() gets corrupted.
If there is a mechanism in newlib to lock the appropriate data
structure, I would appreciate it if this could be added.
--
Joe Buehler
More information about the Newlib
mailing list