Skip to content

Commit

Permalink
Always terminate helper thread when testing suspend. (#400)
Browse files Browse the repository at this point in the history
While working on #399, I found that a failed unit test here resulted in
a segfault.

What happens is the assert exits the test, without stopping the helper
thread. Then the stack is now gone, and the helper thread is using
unallocated memory.

Segfaults in sdunit are hard to diagnose because gdb doesn't have any
clue what the call stack means.
  • Loading branch information
schveiguy authored Oct 23, 2024
1 parent 02d39ff commit 1a8ba56
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions sdlib/d/gc/tstate.d
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ unittest suspend {

auto autoResumeThreadID = runThread(autoResume);

scope(exit) {
mustStop.store(1);

void* ret;
pthread_join(autoResumeThreadID, &ret);
}

void check(SuspendState ss, bool busy, uint suspendCount) {
assert(s.suspendState == ss);
assert(s.busy == busy);
Expand Down Expand Up @@ -287,9 +294,4 @@ unittest suspend {

assert(s.exitBusyState());
check(SuspendState.None, false, 2);

mustStop.store(1);

void* ret;
pthread_join(autoResumeThreadID, &ret);
}

0 comments on commit 1a8ba56

Please sign in to comment.