Skip to content

Commit 08249f1

Browse files
committed
runtime: use CompareAndSwap to avoid racy issue while two threads crash concurrently
1 parent de25957 commit 08249f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/runtime/signal_unix.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,11 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
753753

754754
if docrash {
755755
isCrashThread := false
756-
if crashing.Load() == 0 {
756+
if crashing.CompareAndSwap(0, 1) {
757757
isCrashThread = true
758+
} else {
759+
crashing.Add(1)
758760
}
759-
crashing.Add(1)
760761
if crashing.Load() < mcount()-int32(extraMLength.Load()) {
761762
// There are other m's that need to dump their stacks.
762763
// Relay SIGQUIT to the next m by sending it to the current process.

0 commit comments

Comments
 (0)