Ignore:
Timestamp:
01/31/18 01:24:49 (10 months ago)
Author:
kon
Message:

still obtuse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/synch/trunk/tests/synch-test.scm

    r35091 r35094  
    11;;;; synch test
    22
    3 (use synch srfi-18 srfi-69 miscmacros)
     3(use
     4  test
     5  synch
     6  srfi-18
     7  miscmacros)
     8
     9;;;
     10
     11(define-record-type <foo>
     12  (make-<foo> x y mtx)
     13  <foo>?
     14  (x <foo>-x)
     15  (y <foo>-y)
     16  (mtx <foo>-mutex))
     17
     18(let ((tfoo (make-<foo> 1 2 (make-mutex))))
     19  (test "record-synch" '(1 2)
     20    (record-synch tfoo <foo> (list (<foo>-x tfoo) (<foo>-y tfoo)))) )
     21
     22;;; Synchronize thread access to an object
     23
     24(test-begin "hash-table synch")
    425
    526;;
     
    1334          '?ident) ) ) ) )
    1435
    15 ;;;
     36;;
    1637
    17 (define-record-type <foo>
    18   (make-<foo> x y mtx)
    19   <foo>?
    20   (x <foo>-x)
    21   (y <foo>-y)
    22   (mtx <foo>-mutex))
    23 
    24 (define tfoo (make-<foo> 1 2 (make-mutex)))
    25 (print "*** prints 1 2 ***")
    26 (record-synch <foo> tfoo (print (<foo>-x tfoo) " " (<foo>-y tfoo)))
    27 (newline)
    28 
    29 ;;; Synchronize thread access to an object
    30 
    31 ;;
     38(use srfi-69)
    3239
    3340(define (hash-table-count ht)
     
    3744;;
    3845
    39 (define-constructor-synch make-hash-table hash-table-synch:)
     46(define-constructor-synch make-hash-table)
    4047(define-predicate-synch hash-table?)
    4148(define-operation-synch hash-table-count)
     
    4855(define-constant READER-THREAD-LIMIT 20)
    4956
    50 (define-constant THREAD-SLEEP-MS 0 #;2000)
     57(define-constant THREAD-SLEEP-MS 0)
     58(define-constant READ-FACTOR 1)
     59(define-constant WRITE-FACTOR 1)
    5160
    5261;; Greedy Reader
     
    5766        (print "test hash-table count = " n " so quit"))
    5867    (print "test hash-table count = " n)
    59     (thread-sleep! THREAD-SLEEP-MS) ) )
     68    (thread-sleep! (fx* READ-FACTOR THREAD-SLEEP-MS)) ) )
    6069
    6170;; Cooperative Writer
     
    6574    (hash-table-set!-synch +tht+ it (number->string it))
    6675    (hash-table-set!-synch +tht+ (* it 11) (number->string it))
    67     (thread-sleep! THREAD-SLEEP-MS)
     76    (thread-sleep! (fx* WRITE-FACTOR THREAD-SLEEP-MS))
    6877    (thread-yield!) ) )
    69 
    70 ;;
    7178
    7279(thread-start! writer-thread)
     
    7582(thread-join! writer-thread)
    7683(thread-join! reader-thread)
     84
     85(test-end "hash-table synch")
     86
     87;;
     88
Note: See TracChangeset for help on using the changeset viewer.