Skip to content

Priority queue for the thread_pool #458

@Tearnote

Description

@Tearnote

I'd love to see the feature of being able to provide a priority level for tasks as they're scheduled onto a thread pool. When a worker is free, tasks with higher priority always get scheduled first, and tasks at the same priority are scheduled FIFO. That makes it superset of current behaviour.

In other libraries that support this, the list of available priorities is usually a small compile-time constant, though I'm not sure what implementation considerations cause this. I am reluctant to switch though, mostly due to libcoro's reliable exception safety.

This would cleanly resolve an issue I ran into, where scheduling a long-lived background job, which spawns hundreds of tasks in advance, would starve new foreground jobs until the background job is mostly finished. My current workaround is to have separate thread pools for the two, but that feels suboptimal. Task priorities would allow the same thread pool to yield to the higher priority work, cooperatively. Please let me know if there's something else I can do in the meantime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions