mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-18 21:29:18 +02:00
WIP example
This commit is contained in:
parent
3e1f74278d
commit
d521121f16
1 changed files with 31 additions and 0 deletions
31
examples/threading/join.scm
Normal file
31
examples/threading/join.scm
Normal file
|
@ -0,0 +1,31 @@
|
|||
;;;; 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)
|
Loading…
Add table
Reference in a new issue