[ECOS] pthread_exit() and tss destructors

Robin Farine robin.farine@acn-group.ch
Wed Feb 27 03:56:00 GMT 2002


Hi,

Third-party code using POSIX threads and tss caused me some trouble when
such a thread exited. It turned out that tss destructors got called
multiple times for the same key. According to the POSIX 1003.1 standard,
the code calling these destructors should set each value to NULL before
calling the associated destructor.

The attached patch modifies "pthread.cxx" accordingly.

Robin

2002-02-27  Robin Farine  <robin.farine@terminus.org>

	* src/pthread.cxx (pthread_exit): While running thread static
	storage destructors, sets the thread's value associated with the
	current key to NULL before invoking the destructor.

-------------- next part --------------
Index: base/packages/compat/posix/current/src/pthread.cxx
diff -c base/packages/compat/posix/current/src/pthread.cxx:1.1.1.3 base/packages/compat/posix/current/src/pthread.cxx:1.2
*** base/packages/compat/posix/current/src/pthread.cxx:1.1.1.3	Tue Jan 29 14:07:30 2002
--- base/packages/compat/posix/current/src/pthread.cxx	Wed Feb 27 11:49:19 2002
***************
*** 724,730 ****
                  if( self->thread_data[key] == NULL ) continue;
  
                  // If it passes all that, call the destructor
!                 key_destructor[key]((void *)(self->thread_data[key]));
  
                  // Record that we called a destructor
                  destructors_called = true;
--- 724,734 ----
                  if( self->thread_data[key] == NULL ) continue;
  
                  // If it passes all that, call the destructor
!                 {
!                     void* value = self->thread_data[key];
!                     self->thread_data[key] = NULL;
!                     key_destructor[key](value);
!                 }
  
                  // Record that we called a destructor
                  destructors_called = true;

-------------- next part --------------
-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


More information about the Ecos-discuss mailing list