runtime: don't lock the print output inside interrupts

This should avoid a deadlock when trying to print inside an interrupt,
if the interrupted code is also printing (and therefore has the print
lock taken).
This commit is contained in:
Ayke van Laethem
2025-06-12 13:58:53 +02:00
committed by Ron Evans
parent f7d8502572
commit 5625f68d51
+14 -2
View File
@@ -303,7 +303,16 @@ func systemStackPtr() *uintptr {
const cpuColoredPrint = false
func printlock() {
printLock.Lock()
// Don't lock the print output inside an interrupt.
// Locking the print output inside an interrupt can lead to a deadlock: if
// the interrupt happens while the print lock is held, the interrupt won't
// be able to take this lock anymore.
// This isn't great, but the alternative would be to disable interrupts
// while printing which seems like a worse idea to me.
if !interrupt.In() {
printLock.Lock()
}
if cpuColoredPrint {
switch currentCPU() {
case 1:
@@ -322,5 +331,8 @@ func printunlock() {
printstring("\x1b[0m") // reset colored output
}
}
printLock.Unlock()
if !interrupt.In() {
printLock.Unlock()
}
}