TL;DR
On multiprocessors/multicores engines, more than one RT SCHED_FIFO threads may be scheduled on more than one execution unit. So thread wit
There are a few things obviously wrong with your MCVE:
You have a data race on b
, i.e. undefined behavior, so anything can happen.
You are expecting that the divisor
thread will have finished pthread_setschedparam
call before the ratio
thread gets to computing the ratio.
But there is absolutely no guarantee that the first thread will not run to completion long before the second thread is even created.
Indeed that is what's likely happening under GDB: it must trap thread creation and destruction events in order to keep track of all the threads, and so thread creation under GDB is significantly slower than outside of it.
To fix the second problem, add a counting semaphore, and have both threads randevu after each executed the pthread_setschedparam
call.