Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
429 views
Welcome To Ask or Share your Answers For Others

1 Answer

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});

In Win32 BOOL SetThreadPriority(HANDLE hThread,int nPriority)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...