Skip to content

RunQueue for std.Thread.Pool may not use FILO strategy #21856

@JiaJiaJiang

Description

@JiaJiaJiang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions