Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ mutex locking thread priority

I'm looking to give priority to a thread so that if two threads are waiting for a mutex, the thread with the highest priority will always take the mutex before the lower priority one.

A colleague suggested that by changing the thread priority of my thread I should achieve that. I tried using the SetThreadPriority() function to set one of the waiting threads to 0(normal) and the other one to 2 (highest) but it doesn't affect the mutex behavior like I was hoping. The lock currently always goes to the first thread that requested the ownership.

So is this behavior normal? Contrary to what my colleague thought? Is there a different way to give thread priority that I might be missing? Or am I looking at a more complicated problem to solve?

like image 305
lhbortho Avatar asked May 06 '26 02:05

lhbortho


1 Answers

Thread priority says how much time the thread gets on the CPU as determined by the scheduler, which will preferentially schedule higher priority threads - it doesn't affect the behaviour of mutexes, and I'm not aware of any means of making it do so.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!