Skip to content

<execution>: Should threadpool callback priority be influenced by parent thread priority? #4781

@StephanTLavavej

Description

@StephanTLavavej

Our C++17 parallel algorithms use the Windows threadpool:

: _Ptp_work(::__std_create_threadpool_work(&_Work::_Threadpool_callback, _STD addressof(_Operation), nullptr)) {

[[nodiscard]] PTP_WORK __stdcall __std_create_threadpool_work(
PTP_WORK_CALLBACK _Callback, void* _Context, PTP_CALLBACK_ENVIRON _Callback_environ) noexcept {
return CreateThreadpoolWork(_Callback, _Context, _Callback_environ);
}

We're passing null to CreateThreadpoolWork for the callback environment:

If this parameter is NULL, the callback executes in the default callback environment. For more information, see InitializeThreadpoolEnvironment.

Therefore, the threadpool callbacks have default priority, regardless of the parent thread priority.

Think-cell reported this to us, raising the concern of priority inversion.

In theory, we could alter our code to set up a callback environment, and use SetThreadpoolCallbackPriority to request low, normal, or high priority. However, it is unclear to me whether "The priority for the callback relative to other callbacks in the same thread pool." would control the priority relative to the parent thread, which is what would be needed to address priority inversion concerns.

Ultimately, the conclusion may be that thread priority is outside the realm of the Standard, so if an application has used the Windows API to alter its thread priorities, then the C++17 parallel algorithms are a poor fit for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions