[armedbear-devel] Pure threads and hashtables test
Mark Evenson
evenson at panix.com
Fri Sep 27 12:03:43 UTC 2013
Attached find a test that abstracts all the file i/o away, and seemingly
shows that there *is* a problem with concurrent hashtables access to ABCL.
CL-USER> (run 1)
Spawning 1 threads... Done.
Spawned threads that should sum to 10 while the shared value is 10.
NIL
CL-USER> (run 10)
Spawning 10 threads... Done.
Spawned threads that should sum to 100 while the shared value is 100.
NIL
CL-USER> (run 100)
Spawning 100 threads... Done.
Spawned threads that should sum to 1000 while the shared value is 993.
NIL
In this test, each thread sleeps for (/ (random 1000) 1000) seconds to
allow contentions to arise.
Inspection of the code and observations of whether this test should be
expected to "fail" for some other problem are solicited.
--
"A screaming comes across the sky. It has happened before, but there
is nothing to compare to it now."
-------------- next part --------------
;;; Test for shared writes to a single hash entry for ABCL
#|
Use:
(run 2)
(run 1000)
|#
(defparameter *shared* (make-hash-table :test 'equal))
(defun increment (n)
(sleep (/ (random 1000) 1000))
(loop :for i :below n
:doing (progn
(sleep (/ (random 1000) 1000))
(setf (gethash 1 *shared*)
(1+ (or (gethash 1 *shared*)
0)))))
n)
(defun run (threads)
(clrhash *shared*)
(format t "~&Spawning ~A threads..." threads)
(format t " Done.~%Spawned threads that should sum to ~A while the shared value is ~A.~%"
(loop :for thread :in
(loop :for i :below threads
:collect (threads:make-thread (lambda () (increment 10))))
:summing (threads:thread-join thread))
(gethash 1 *shared*)))
More information about the armedbear-devel
mailing list