Re: state-threads / pthreads interaction on Linux
Gene Shekhtman <[email protected]> Tue, 26 Nov 2002 21:22:40 -0800
| Newsgroups | gmane.comp.lib.state-threads.user |
|---|---|
| Message-ID | <[email protected]> |
Sascha Schumann wrote:
>
> Hi,
>
> has anyone encountered the problem that it is apparently
> impossible to mix state threads and the pthreads library on
> Linux?
>
> Whenever I access errno in a st-managed thread, I get a
> segfault. This is especially true for library wrappers such
> as connect() etc.
>
I did some digging in the linuxthreads source. I think the
culprit is in the inlined function thread_self() which is called
by __errno_location(). That function relies on stack pointer to
get pthread's identity. The "stack pointer" is just an address
of a local variable:
#define CURRENT_STACK_FRAME ({ char __csf; &__csf; })
char *sp = CURRENT_STACK_FRAME;
In other words, libpthread assumes that there is only one stack
per each pthread and thus thread id can be inferred from the
stack pointer. If there are stack segments other than created
by libpthread, thread_self() may return bogus thread id.
The bottom line, I guess, is that current pthreads implementation
cannot be mixed with any other thread library.
--Gene
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T
handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en