[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

How do I detect when a new thread is finished?

Thanks Roland.

It is rather unfortunate that I have to go through all
this effort - while all I need is to free Thread Specific Data
at thread termination.

The reason that I cannot use `pthread_key_create' for this
TSD is because I still need the TSD during calls to free().

NPTL's `deallocate_tsd' calls the user destructors in
arbitrary order - so I cannot be 100% sure that no user code
will be executed after the key destruction routine that
I passed, was called.  Moreover - after that, it calls free()
to free the level2 key blocks and after that
`__libc_thread_freeres()' which might also call free()
(I can't add my own hook there, can I?).

Would I have the same problems with TLS?  If not, then I might
just stop supporting compilers that don't support __thread.

It is very unclear to me when the TLS is destructed and wether
or not subsequential calls to free() will follow.

To summarize,
what I need eventually is this:

  Thread exiting/cancelled/joining...
  --> Last call to user provided code (pthread key destruction routine?)
  --> Last call to free() (or malloc/calloc/realloc)
  --> Call to my hook function.  This function would free the
      thread specific data that I need inside malloc et al,
      it would use a special 'free' - not a normal 'free()'.

All help is greatly appreciated.

Carlo Wood <carlo alinoe com>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]