Boost logo

Boost Users :

From: Gavin Lambert (boost_at_[hidden])
Date: 2021-10-07 22:40:08

On 7/10/2021 22:09, Alexander Carôt wrote:
> I had been using an old boost system and boost thread lib for a couple of years without upgrading it since approx. 2014. With this old lib the following (simplified) code works fine on OSX:
> #include "test.h"
> test::test() {
> boost::thread::attributes attrs;
> res =
> SetThreadPriority(attrs.native_handle(), THREAD_PRIORITY_NORMAL);
> pthread_attr_setschedpolicy(attrs.native_handle(), SCHED_FIFO);
> #endif
> tracerouteThread = boost::thread(
> attrs, boost::bind(&test::performTraceroute, this));

For Win32, you can't call SetThreadPriority like that -- at best, that's
doing nothing, at worst, you're changing the priority of some random
thread but never the one you intend. (The attrs.native_handle is not a
thread handle.)

You must wait until the thread is actually started before you can set
its priority. Usually the best place to set it is from the thread's
method itself.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at