I linked that for another MR, but it could be useful here too https://gitlab.winehq.org/wine/wine/-/merge_requests/6783#note_87504. Sample implementation always grab its own lock, checks for its own shutdown status, and does not call to the event queue if container object is shut down already. I don't know if it helps or not, or if this sample is thread safe in a first place.