Created
January 4, 2019 20:01
-
-
Save b4284/86f53ec29cb5aefe759f2e338fc89872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (ice-9 threads)) | |
(define mtx (make-mutex)) | |
(define cv (make-condition-variable)) | |
(define v 0) | |
(lock-mutex mtx) ;; Lock first to declare master thread | |
(define t | |
(call-with-new-thread | |
(lambda () | |
(let A () | |
(lock-mutex mtx) | |
(set! v (+ v 1)) | |
(format #t "A: v=~a~%" v) | |
(signal-condition-variable cv) | |
(wait-condition-variable cv mtx) | |
(unlock-mutex mtx) | |
(A))))) | |
(let B () | |
(set! v (+ v 1)) | |
(format #t "B: v=~a~%" v) | |
(signal-condition-variable cv) | |
(wait-condition-variable cv mtx) | |
(B)) | |
(join-thread t) | |
;; (let B () | |
;; (set! v (+ v 1)) | |
;; (format #t "B: v=~a~%" v) | |
;; (unlock-mutex mtx) | |
;; (signal-condition-variable cv) | |
;; (B)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment