[openib-general] [PATCH] osm: cl_timer.c segfault on exit

Eitan Zahavi eitan at mellanox.co.il
Mon Jan 9 06:23:26 PST 2006


Hi Hal

We observed a race on closing of complib on some machines.
Tracing down the bug we have found the code on destruction
of the global complib timer - to be the couse of it.

The fix goes back to use standard pthread_join and avoid the 
while loop...

Thanks

Eitan

Signed-off-by:  Eitan Zahavi <eitan at mellanox.co.il>

Index: complib/cl_timer.c
===================================================================
--- complib/cl_timer.c	(revision 4706)
+++ complib/cl_timer.c	(working copy)
@@ -112,30 +112,24 @@ void
 __cl_timer_prov_destroy( void )
 {
 
-  cl_timer_prov_t *tmp_gp_timer_prov = gp_timer_prov;
+  pthread_t tid;
 
   if( !gp_timer_prov )
     return;
  
-  /* keep sending cond events untill it exited */
-  while (tmp_gp_timer_prov->thread != 0)
-  {
-    /* signal the thread to exit. */
-    pthread_mutex_lock( &tmp_gp_timer_prov->mutex );
-    tmp_gp_timer_prov->exit = TRUE;
-   
-    pthread_cond_broadcast( &tmp_gp_timer_prov->cond );
-   
-    /* Broadcast might be prefered on pthread_cond_signal */
-    pthread_mutex_unlock( &tmp_gp_timer_prov->mutex );
-  }
+  tid = gp_timer_prov->thread;
+  pthread_mutex_lock( &gp_timer_prov->mutex );
+  gp_timer_prov->exit = TRUE;
+  pthread_cond_broadcast( &gp_timer_prov->cond );
+  pthread_mutex_unlock( &gp_timer_prov->mutex );
+  pthread_join( tid , NULL );
  
   /* Destroy the mutex and condition variable. */
-  pthread_mutex_destroy( &tmp_gp_timer_prov->mutex );
-  pthread_cond_destroy( &tmp_gp_timer_prov->cond );
+  pthread_mutex_destroy( &gp_timer_prov->mutex );
+  pthread_cond_destroy( &gp_timer_prov->cond );
 
   /* Free the memory and reset the global pointer. */
-  cl_free( tmp_gp_timer_prov );
+  cl_free( gp_timer_prov );
   gp_timer_prov = NULL;
 }
 




More information about the general mailing list