Refactoring of test code

This commit is contained in:
Justin Ethier 2019-06-13 13:19:15 -04:00
parent e35c909ce3
commit 2eeae1d7ed
4 changed files with 17 additions and 10 deletions

View file

@ -10,6 +10,9 @@ TARGETS = \
threading/many-writers \
threading/producer-consumer \
threading/thread-join \
threading/sum-atomic \
threading/sum-mutex \
threading/sum-nosync \
game-of-life/life \
hello-library/hello \
@ -37,6 +40,12 @@ threading/producer-consumer: threading/producer-consumer.scm
cyclone $^
threading/thread-join : threading/thread-join.scm
cyclone $^
threading/sum-atomic : threading/sum-atomic.scm
cyclone $^
threading/sum-mutex : threading/sum-mutex.scm
cyclone $^
threading/sum-nosync : threading/sum-nosync.scm
cyclone $^
game-of-life/life:
cd game-of-life ; make
hello-library/hello:

View file

@ -1,4 +1,4 @@
;;;; A simple example of using a condition variable to simulate thread-join
;;;; Example of having multiple threads sum a variable using an atom.
(import (scheme base)
(scheme read)
(scheme write)
@ -18,7 +18,7 @@
(sum-loop (- n 1))))
(define (sum-entry-pt)
(sum-loop (* 10 100 100 100)))
(sum-loop (* 100 100 100)))
;; Thread - Do something, then let main thread know when we are done
(define t1 (make-thread sum-entry-pt))
@ -50,5 +50,5 @@
(thread-join! t8)
(thread-join! t9)
(display "main thread done, sum = ")
(display (ref *sum*))
(display (deref *sum*))
(newline)

View file

@ -1,4 +1,4 @@
;;;; A simple example of using a condition variable to simulate thread-join
;;;; Example of using a mutex to synchronize summing of a variable by multiple threads.
(import (scheme base)
(scheme read)
(scheme write)
@ -19,7 +19,7 @@
(sum-loop (- n 1))))
(define (sum-entry-pt)
(sum-loop (* 10 100 100 100)))
(sum-loop (* 100 100 100)))
;; Thread - Do something, then let main thread know when we are done
(define t1 (make-thread sum-entry-pt))

View file

@ -1,12 +1,10 @@
;;;; A simple example of using a condition variable to simulate thread-join
;;;; Example of using multiple threads to sum a variable without synchronization.
;;;; Returns inconsistent and wrong results due to a lack of thread coordination.
(import (scheme base)
(scheme read)
(scheme write)
(srfi 18))
;(define cv (make-condition-variable))
;(define m (make-mutex))
(define *sum* 0)
(define (sum-loop n)
@ -16,7 +14,7 @@
(sum-loop (- n 1))))
(define (sum-entry-pt)
(sum-loop (* 10 100 100 100)))
(sum-loop (* 100 100 100)))
;; Thread - Do something, then let main thread know when we are done
(define t1 (make-thread sum-entry-pt))