mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
Initial file
This commit is contained in:
parent
22ca4ff85a
commit
c49c753f9d
1 changed files with 41 additions and 0 deletions
41
libs/test-threads.scm
Normal file
41
libs/test-threads.scm
Normal file
|
@ -0,0 +1,41 @@
|
|||
;;;; 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 - Do something, then let main thread know when we are done
|
||||
(define t
|
||||
(make-thread
|
||||
(lambda ()
|
||||
(display "started thread")
|
||||
(newline)
|
||||
(thread-sleep! 3)
|
||||
(display "thread done")
|
||||
(newline)
|
||||
;(thread-terminate!)
|
||||
)))
|
||||
|
||||
(define t2
|
||||
(make-thread
|
||||
(lambda ()
|
||||
(display "started thread2")
|
||||
(newline)
|
||||
(thread-sleep! 4)
|
||||
(display "thread2 done")
|
||||
(newline)
|
||||
;(thread-terminate!)
|
||||
)))
|
||||
(thread-start! t)
|
||||
(thread-start! t2)
|
||||
|
||||
(write (thread? t))
|
||||
(thread-sleep! 1)
|
||||
;; Main thread - wait for thread to broadcast it is done
|
||||
(thread-join! t)
|
||||
(thread-join! t2)
|
||||
(display "main thread done")
|
||||
(newline)
|
Loading…
Add table
Reference in a new issue