Skip to content

Instantly share code, notes, and snippets.

@fakedrake
Created October 2, 2021 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakedrake/89a6ddf22616af004010d23d29342881 to your computer and use it in GitHub Desktop.
Save fakedrake/89a6ddf22616af004010d23d29342881 to your computer and use it in GitHub Desktop.
(defmacro with-repeating (threads repetitions &rest body)
`(mapc #'sb-thread:join-thread
(loop repeat ,threads
collect (sb-thread:make-thread
(lambda () (loop repeat ,repetitions do ,@body))))))
(defstruct atomic-var
(data 0 :type (unsigned-byte 64)))
(proclaim '(optimize (safety 0) (speed 3)))
(defun increment-value ()
(let ((x (make-atomic-var :data 0)))
(with-repeating 1000 1000
(sb-ext:atomic-incf (atomic-var-data x) 1))
x))
;; The below numbers are almost identical with and without proclaim.
;;
;; CL-USER> (time (increment-value))
;; Evaluation took:
;; 0.052 seconds of real time
;; 0.087489 seconds of total run time (0.059310 user, 0.028179 system)
;; 167.31% CPU
;; 908,464 bytes consed
;;
;; #S(ATOMIC-VAR :DATA 1000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment