Skip to content

Commit

Permalink
Locality-aware task stealing
Browse files Browse the repository at this point in the history
  • Loading branch information
pkhuong committed Dec 20, 2011
1 parent 533cd3f commit c78d551
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions thread-pool.lisp
Expand Up @@ -55,13 +55,17 @@
(let ((task (sb-queue:dequeue queue)))
(when task
(return-from grab-task task)))
(let ((n (length stacks)))
(dotimes (j n)
(let* ((i (mod (+ i j) n))
(task (or (work-stack:steal (aref stacks i))
(sb-queue:dequeue queue))))
(when task
(return-from grab-task task))))))
(let* ((n (length stacks))
(power-of-two (ash 1 (integer-length (1- n)))))
(dotimes (j power-of-two)
(let ((i (logxor i j)))
(when (>= i n)
(go skip))
(let ((task (or (work-stack:steal (aref stacks i))
(sb-queue:dequeue queue))))
(when task
(return-from grab-task task))))
skip)))

(defvar *worker-id* nil)
(defvar *worker-hint* 0)
Expand Down

0 comments on commit c78d551

Please sign in to comment.