;;; 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*)))