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;
/// START TRACEROUTE THREAD #if defined(BOOST_THREAD_PLATFORM_WIN32) res = SetThreadPriority(attrs.native_handle(), THREAD_PRIORITY_NORMAL); #elif defined(BOOST_THREAD_PLATFORM_PTHREAD) 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.