@@ -294,6 +294,11 @@ namespace ocs {
294294 // do not exit even if event client shutdown event is received. We want the thread only to terminate in the cancellation
295295 // point to enforce that: other threads (accessing the data store) terminate before us and we need to do the
296296 // cleanup (free of data store memory and more) at the cancellation point
297+
298+ // the thread shall only terminate in pthread_testcancel() to ensure that proper cleanup is done
299+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, nullptr );
300+ pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, nullptr );
301+
297302 bool do_qmaster_shutdown = false ;
298303 while (true ) {
299304 lList *event_list = nullptr ;
@@ -389,10 +394,12 @@ namespace ocs {
389394 // We just wait here for the final termination signal to do the cleanup.
390395 do {
391396 int execute = 0 ;
392- pthread_cleanup_push (thread_cleanup_monitor, &monitor);
397+ pthread_cleanup_push (thread_cleanup_monitor, static_cast < void *>( &monitor) );
393398 pthread_cleanup_push (thread_cleanup_data_store, nullptr );
394- pthread_cleanup_push (thread_cleanup_event_client, evc);
399+ pthread_cleanup_push (thread_cleanup_event_client, static_cast <void *>(evc));
400+ pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, nullptr );
395401 pthread_testcancel ();
402+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, nullptr );
396403 pthread_cleanup_pop (execute); // event client registration
397404 pthread_cleanup_pop (execute); // data store that was filled by this mirror
398405 pthread_cleanup_pop (execute); // monitor
0 commit comments