Commit 39363f1c authored by Julien Jerphanion's avatar Julien Jerphanion

Add queue to workers randomly

Round robin is not thread safe.

It would require putting an atomic on ``next_worker``
which would probably slow dispatching queues.

Hence prefering random dispath.
parent 27426854
......@@ -104,7 +104,6 @@ cdef cypclass Scheduler:
pthread_barrier_t barrier
sem_t num_free_queues
atomic[int] num_pending_queues
int next_worker
int num_workers
sem_t done
volatile bint is_done
......@@ -113,7 +112,6 @@ cdef cypclass Scheduler:
self = <lock Scheduler> consume alloc()
if num_workers == 0: num_workers = sysconf(_SC_NPROCESSORS_ONLN)
self.num_workers = num_workers
self.next_worker = 0
sem_init(&self.num_free_queues, 0, 0)
sem_init(&self.done, 0, 0)
self.num_pending_queues.store(0)
......@@ -141,9 +139,8 @@ cdef cypclass Scheduler:
sem_destroy(&self.done)
void post_queue(self, lock SequentialMailBox queue):
# Add a queue to workers in round robin
worker = self.workers[<int> self.next_worker]
self.next_worker = (self.next_worker + 1) % self.num_workers
# Add a queue to workers randomly
worker = self.workers[<int> rand() % self.num_workers]
with wlocked worker:
queue.has_worker = True
worker.queues.push_back(queue)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment