Skip to content

Commit aeedef9

Browse files
committed
Release the task queue lock while running cancel handlers
em_task_queue_cancel ran cancel handlers with the queue lock held. A handler can block, and a blocked thread processes its dlopen queue, which can be the queue being cancelled: a thread exiting during dlopen() then deadlocks on its own lock. em_task_queue_execute already unlocks around tasks. See #18887.
1 parent e52f8cf commit aeedef9

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎system/lib/pthread/em_task_queue.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ void em_task_queue_cancel(em_task_queue* queue) {
188188
while (!em_task_queue_is_empty(queue)) {
189189
task t = em_task_queue_dequeue(queue);
190190
if (t.cancel) {
191+
// Release the lock while running the handler, as in
192+
// em_task_queue_execute. The handler can block, and a blocked thread
193+
// processes its dlopen queue, which can be this queue.
194+
pthread_mutex_unlock(&queue->mutex);
191195
t.cancel(t.arg);
196+
pthread_mutex_lock(&queue->mutex);
192197
}
193198
}
194199
pthread_mutex_unlock(&queue->mutex);

0 commit comments

Comments
 (0)