Closed tihmstar closed 3 years ago
Didn't work with my test case which is literally just
irecv_device_event_context_t context = NULL;
irecv_device_event_subscribe(&context, irecv_device_cb, NULL);
irecv_device_event_unsubscribe(context);
So I came up with a different solution that makes sure irecv_device_event_subscribe()
doesn't return before the thread has started and reached a certain point (right before CFRunLoopRun()
in case of macOS).
See commit 5718dd2ae149f615191552eef40f8f90e60a3455.
Doesn't that hide the issue even more? I mean the race is still there.
There is a racecondition when you call irecv_device_event_unsubscribe shortly after irecv_device_event_subscribe. If the
_irecv_event_handler
thread didn't reachCFRunLoopRun();
beforeirecv_device_event_unsubscribe
callsCFRunLoopStop()
, the call doesn't actually stop the runloop and thenirecv_device_event_unsubscribe
hangs forever atthread_join(th_event_handler);
.This patch makes sure that CFRunloop is actually idle, before calling
CFRunLoopStop
.