Skip to content

Instantly share code, notes, and snippets.

@marler8997
Created December 16, 2020 03:23
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 marler8997/27b8f24475326a65007d9943c88122f6 to your computer and use it in GitHub Desktop.
Save marler8997/27b8f24475326a65007d9943c88122f6 to your computer and use it in GitHub Desktop.
fn runWorker(self: *ThreadPool) void {
const old_pool = tls_current_pool;
tls_current_pool = self;
defer tls_current_pool = old_pool;
while (true) {
const held = self.mutex.acquire();
if (self.is_shutdown) {
held.release();
break;
}
if (self.run_queue.pop()) |runnable| {
held.release();
(runnable.callback)(runnable);
continue;
}
var idle_node = IdleQueue.Node{ .data = .{} };
self.idle_queue.prepend(&idle_node);
held.release();
idle_node.data.wait();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment