3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package :sb-concurrency-test)
14 (defun test-frlocks (&key (reader-count 100) (read-count 1000000)
15 (outer-read-pause 0) (inner-read-pause 0)
16 (writer-count 10) (write-count 10000)
17 (outer-write-pause 0.0001) (inner-write-pause 0))
18 (let ((rw (make-frlock))
23 (w-e! (cons :write-oops nil))
24 (r-e! (cons :read-oops nil)))
25 (flet ((maybe-pause (pause &optional value)
27 (sb-thread:thread-yield)
29 (sleep (random pause))))
33 (loop repeat reader-count
37 (loop until run! do (thread-yield))
39 (loop repeat read-count
40 do (multiple-value-bind (a b c)
42 a b (maybe-pause inner-read-pause c))
43 (maybe-pause outer-read-pause)
44 (unless (eql c (+ a b))
45 (sb-ext:atomic-update (cdr r-e!) #'cons
48 (sb-ext:atomic-update (cdr r-e!) #'cons e))))))
49 (loop repeat writer-count
52 (loop until run! do (thread-yield))
54 (loop repeat write-count
56 (let* ((a_ (random 10000))
62 (maybe-pause inner-write-pause)
63 (unless (and (eql c c_)
66 (sb-ext:atomic-update (cdr w-e!) #'cons
67 (list a a_ b b_ c c_)))))
68 (maybe-pause outer-write-pause))
70 (sb-ext:atomic-update (cdr w-e!) #'cons e))))))
74 (values (cdr w-e!) (cdr r-e!))))