[Gc] Re: using threads that were not created by GC_pthread_create()

eric lindvall eric@5stops.com
Thu, 24 Jul 2003 16:31:40 -0700

On Thu, 24 Jul 2003, Boehm, Hans wrote:

> I think it would be tricky to do that without cooperation of the thread itself.
> You can certainly get the thread id, and you might be able to get the cold stack end,
> depending on your platform.  But getting those in and out of the thread table without
> introducing a race sounds quite tricky.  By the time you get a thread id into the table,
> it may have been reused for another thread with a different stack.  The thread-local 
> allocation code would probably also have to be restructured or turned off.
> Even if the thread can cooperate, the code isn't currently structured to make that
> easily possible.  But I wouldn't be at all opposed to fixing that.  (It would have
> to cooperate to register itself, and to unregister itself on the way out.)

What do you mean by "cooperation"? My code is called into on a thread, so
I would assume I can make any pthread or system calls I want to.

> Depending on the definition of "module" and on your environment, another possible solution
> sometimes is to play linker games to intercept pthread_create, e.g. to preload a library
> that defines pthread_create,
> and then uses dlopen and dlsym internally to call the pthread version.  (This is done by
> the wrap.h header in https://www.hpl.hp.com/personal/Hans_Boehm/qprof/qprof-0.2.tar.gz ,
> among other places.)  The collector will probably acquire built-in support for doing some
> of this shortly, at least on linux.

While the preloading thing is a possibility, it isn't something I would
like to do, and would choose other solutions if it came down to that.

Thank you for your response.