This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

wait-condition-variable & select


Sascha Ziemann writes:
 >  - How can I unify this? I need a way to wait at the same time for a
 >    change of a conditional variable and for a change on a port.

How about following?

;;;
(define event (make-condition-variable))

;; In a thread, "select" the condition for file descripter.
;; When event occurs, set flag and signal this event.
...
   (select ...)
   ;; Set a flag
   ...
   (signal-condition-variable event)
   ...

;; In another thread, when some other conditions met,
;; set other flags and signal event
...
   ;; some condition
   ;; Set some flags 
   ...
   (signal-condition-variable event)
   ...

;; Waiting thread on event
;; To see which event occurs (select or other),
;; check the flags
...
   (wait-condition-variable event mutex)
   ;; check flags and dispatch

Hope this helps.

BTW, I think that there is a (severe) race condition in the current
thread implementation of Guile.  SCM_NEWCELL should be protected.
Consider two or more thread racing on SCM_NEWCELL.
-- 
NIIBE Yutaka