[mcclim-devel] Threading and Waiting
John Connors
johnc at yagc.ndo.co.uk
Tue Feb 14 09:58:10 UTC 2006
While looking for the 'right' way to get a SCBL thread to wait for a specified
condition as part of an attempt to update port from the CLOCC, I came across
this gem in the McCLIM sources.
(declaim (inline yield))
(defun yield ()
(declare (optimize speed (safety 0)))
(sb-alien:alien-funcall
(sb-alien:extern-alien "sched_yield" (function sb-alien:int)))
(values))
(defun process-wait (reason predicate)
(let ((old-state (process-whostate *current-process*)))
(unwind-protect
(progn
(setf old-state (process-whostate *current-process*)
(process-whostate *current-process*) reason)
(loop
(let ((it (funcall predicate)))
(when it (return it)))
;(sleep .01)
(yield)))
(setf (process-whostate *current-process*) old-state))))
Now this will work, but my understanding is when calling sched_yeild, a thread
gets completely expired and put at the back of the scheduling queue. What was/is
wrong with sleep?
More information about the mcclim-devel
mailing list