Zig Version
0.14.0-dev.2051+b1361f237
Steps to Reproduce and Observed Behavior
In std thread pool, all "spawn" methods will add new tasks to the beginning of the queue:
|
pool.run_queue.prepend(&closure.run_node); |
|
pool.run_queue.prepend(&closure.run_node); |
|
pool.run_queue.prepend(&closure.run_node); |
However, the worker will get the task from the beginning of the queue too:
|
while (pool.run_queue.popFirst()) |run_node| { |
|
if (pool.run_queue.popFirst()) |run_node| { |
Therefore, the thread pool queue uses the first-in-last-out strategy (FILO), which means that if tasks are added frequently, the first set task may wait for a long time before being executed, or may even never be executed. I think this strategy is not compatible with the task queue.
Expected Behavior
It should use the first-in-first-out (FIFO) strategy to ensure that the first set task is executed first, which is not only in line with program logic, but also more intuitive.
Zig Version
0.14.0-dev.2051+b1361f237
Steps to Reproduce and Observed Behavior
In std thread pool, all "spawn" methods will add new tasks to the beginning of the queue:
zig/lib/std/Thread/Pool.zig
Line 142 in c39ba68
zig/lib/std/Thread/Pool.zig
Line 206 in c39ba68
zig/lib/std/Thread/Pool.zig
Line 250 in c39ba68
However, the worker will get the task from the beginning of the queue too:
zig/lib/std/Thread/Pool.zig
Line 286 in c39ba68
zig/lib/std/Thread/Pool.zig
Line 308 in c39ba68
Therefore, the thread pool queue uses the first-in-last-out strategy (FILO), which means that if tasks are added frequently, the first set task may wait for a long time before being executed, or may even never be executed. I think this strategy is not compatible with the task queue.
Expected Behavior
It should use the first-in-first-out (FIFO) strategy to ensure that the first set task is executed first, which is not only in line with program logic, but also more intuitive.