mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-21 12:59:04 +00:00
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:
committed by
Ron Evans
parent
f7d8502572
commit
5625f68d51
@@ -303,7 +303,16 @@ func systemStackPtr() *uintptr {
|
|||||||
const cpuColoredPrint = false
|
const cpuColoredPrint = false
|
||||||
|
|
||||||
func printlock() {
|
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 {
|
if cpuColoredPrint {
|
||||||
switch currentCPU() {
|
switch currentCPU() {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -322,5 +331,8 @@ func printunlock() {
|
|||||||
printstring("\x1b[0m") // reset colored output
|
printstring("\x1b[0m") // reset colored output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printLock.Unlock()
|
|
||||||
|
if !interrupt.In() {
|
||||||
|
printLock.Unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user