Portable way of setting std::thread priority in C++11

Gerdiner picture Gerdiner · Sep 19, 2013 · Viewed 54.8k times · Source

What is the correct way in the post C++11 world for setting the priority of an instance of std::thread

Is there a portable way of doing this that works at least in Windows and POSIX (Linux) environments?

Or is it a matter of getting a handle and using whatever native calls are available for the particular OS?

Answer

Mike Seymour picture Mike Seymour · Sep 19, 2013

There's no way to set thread priorities via the C++11 library. I don't think this is going to change in C++14, and my crystal ball is too hazy to comment on versions after that.

In POSIX, pthread_setschedparam(thread.native_handle(), policy, {priority});

I don't know the equivalent Windows function, but I'm sure there must be one.