(zilch statusbar): fix the deadlock

The statusbar code contained a deadlock in error cases, which, somehow,
was a heisenbug. After a 2-hour long debugging session today, it has
finally been spotted and _solved_.

I should some day move off Chicken Scheme.

Change-Id: If0c2a2b6db10b5620c12f191f13af4c86a6a6964
This commit is contained in:
puck 2025-11-24 18:37:10 +00:00
parent de26625157
commit ace83f3b1b

View file

@ -40,7 +40,22 @@
(when start
(redraw-status-bar))
(mutex-unlock! mutex))))
(make-output-port (lambda (str) (mutex-lock! mutex) (write-data (string->utf8 str) 0)) close-this-port))
(make-output-port
(lambda (str)
; In some rare cases, due to how Chicken Scheme handles errors,
; it is possible for us to seemingly recursively have been called
; while in the error handler. If this is the case (e.g. we are about
; to attempt to lock a mutex we ostensibly own), bail out and unlock
; the mutex.
(when (eq? (mutex-state mutex) (current-thread))
(mutex-unlock! mutex))
; Try to force-disable the error handling behavior.
(##sys#print-length-limit #f)
(mutex-lock! mutex)
(write-data (string->utf8 str) 0))
close-this-port))
;; Creates a status bar. Ensures redraws are limited where necessary, and will erase itself before printing `stdout`. `stderr` output will be put in the statusbar.
;; if `print-logs` is `#t`, will output stderr to the display.