Skip to content

fix: crash on exit when a thread is blocked in a queue being destroyed - #156

Open
HopeSuffers wants to merge 1 commit into
N64Recomp:mainfrom
HopeSuffers:fix/exit-queue-destruction
Open

HopeSuffers wants to merge 1 commit into
N64Recomp:mainfrom
HopeSuffers:fix/exit-queue-destruction

Conversation

@HopeSuffers

Copy link
Copy Markdown

Quitting the game sometimes segfaults. It's always a null deref in LightweightSemaphore::tryWait(), on whatever thread happened to be waiting on a queue, while the main thread is busy running static destructors.

What's going on is that recomp::start() joins the game thread, the event threads, the thread cleaner and the saving thread on the way out, but two things never get stopped at all:

  • the timer thread, which is detached in init_timers, so nobody waits for it
  • the game threads, which sit in pause_self() forever

Those are the two that crash. The other queues survive because their threads are gone by the time exit() gets around to destroying anything. These two are still parked inside theirs.

For the timer thread I drop a stop action in the queue and add a join_timer_thread() next to the other join_* calls. Pretty much the same as the null OSTask that already stops the SP task thread.

The game threads pause_self() is a while (true) with no way out, so I left them alone and made external_messages a leaked function-local static instead. Nothing destroys it any more and they just stay parked until the process goes away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant