void WorkerTaskDispatcher::coordinator_distribute_task(WorkerTask* task, uint num_workers) { // No workers are allowed to read the state variables until they have been signaled.
_task = task;
_not_finished = num_workers;
// Dispatch 'num_workers' number of tasks.
_start_semaphore.signal(num_workers);
// Wait for the last worker to signal the coordinator.
_end_semaphore.wait();
// No workers are allowed to read the state variables after the coordinator has been signaled.
assert(_not_finished == 0, "%d not finished workers?", _not_finished);
_task = NULL;
_started = 0;
}
void WorkerTaskDispatcher::worker_run_task() { // Wait for the coordinator to dispatch a task.
_start_semaphore.wait();
// Get and set worker id. const uint worker_id = Atomic::fetch_and_add(&_started, 1u);
WorkerThread::set_worker_id(worker_id);
// Run task.
GCIdMark gc_id_mark(_task->gc_id());
_task->work(worker_id);
// Mark that the worker is done with the task. // The worker is not allowed to read the state variables after this line. const uint not_finished = Atomic::sub(&_not_finished, 1u);
// The last worker signals to the coordinator that all work is completed. if (not_finished == 0) {
_end_semaphore.signal();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.