wrong exit code with linux threads
Tor Egge
Tor.Egge at cvsup.no.freebsd.org
Thu Feb 3 20:08:46 PST 2005
>
> Hi,
>
> the program below (tmp.c) gives strange output regarding the child exit
> status when using linux threads on freebsd 4.7.
>
> With lib pthread- correct:
> Exit value 123
> Exit value 123
>
> With llthread - error:
> Exit value 123
> Exit value 0
>
> Any ideas?
exit handling is known to be broken in the linuxthreads port, e.g. if one
thread calls exit while other threads are still running then atexit handlers
registered after the one registered by pthread_initialize() are called, and
data structures might be removed while still being used by other threads.
atexit handlers registered before the one registered by pthread_initialize()
might not be called at all, since if other threads were killed while holding
mutexes then the program would just hang. The exit code is not available for
functions registered with atexit(), so terminating early with the exit code
passed to exit is not easily done.
Additionally, the command "gcc -o tmp tmp.c -L/usr/local/lib -llthread" is
wrong unless you've compiled the linuxthread port with support for emulating
the ABI for native threads (LINUXTHREADS_WRAP_API=yes). You need to specify
where to find the corresponding header files,
i.e. "-I/usr/local/include/pthread/linuxthreads" has to be added to the
command.
If you compile the linuxthreads port with LINUXTHREADS_DETECT_UNSAFE_EXIT=yes
then your sample program seems to exit with the correct exit code. But that
has other side effects, e.g. when it was implicit in version 2.2.3_9 of the
linuxthreads port, people reported that /usr/local/bin/mysql_install_db checked
the exit code of mysqld and aborted.
- Tor Egge
More information about the freebsd-threads
mailing list