Commit 7b12b3f0 authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Ben Gamari
Browse files

itimer: Don't free condvar until we know ticker is stopped

When we are shutting down the pthread ticker we signal the start_cond condition
variable to ensure that the ticker thread wakes up and exits in a reasonable
amount of time. Previously, when the ticker thread would shut down it was
responsible for freeing the start_cond condition variable. However, this would
lead to a race wherein the ticker would free start_cond, then the main thread
would try to signal it in an effort to wake the ticker (#16150).

Avoid this by moving the mutex destruction to the main thread.
parent 4ad9ffd3
...@@ -147,8 +147,6 @@ static void *itimer_thread_func(void *_handle_tick) ...@@ -147,8 +147,6 @@ static void *itimer_thread_func(void *_handle_tick)
if (USE_TIMERFD_FOR_ITIMER) if (USE_TIMERFD_FOR_ITIMER)
close(timerfd); close(timerfd);
closeMutex(&mutex);
closeCondition(&start_cond);
return NULL; return NULL;
} }
...@@ -207,6 +205,8 @@ exitTicker (bool wait) ...@@ -207,6 +205,8 @@ exitTicker (bool wait)
if (pthread_join(thread, NULL)) { if (pthread_join(thread, NULL)) {
sysErrorBelch("Itimer: Failed to join"); sysErrorBelch("Itimer: Failed to join");
} }
closeMutex(&mutex);
closeCondition(&start_cond);
} else { } else {
pthread_detach(thread); pthread_detach(thread);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment