mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 13:05:05 +02:00
31 lines
795 B
Scheme
31 lines
795 B
Scheme
;;;; A simple example of using a condition variable to simulate thread-join
|
|
(import (scheme base)
|
|
(scheme read)
|
|
(scheme write)
|
|
(srfi 18))
|
|
|
|
(define cv (make-condition-variable))
|
|
(define m (make-mutex))
|
|
|
|
(thread-start!
|
|
(make-thread
|
|
(lambda ()
|
|
(write "started thread")
|
|
(thread-sleep! 5000)
|
|
(condition-variable-broadcast! cv)
|
|
(write "thread done"))))
|
|
|
|
(thread-start!
|
|
(make-thread
|
|
(lambda ()
|
|
(write "started waiting thread")
|
|
(mutex-lock! m)
|
|
(write "register waiting thread cv")
|
|
(mutex-unlock! m cv)
|
|
;; TODO: think this is never printed because mutex is locked after waking up..
|
|
(write "waiting thread done"))))
|
|
|
|
(mutex-lock! m)
|
|
(mutex-unlock! m cv) ;; Wait on cv
|
|
(write "main thread done")
|
|
(thread-sleep! 500)
|