Linux not respecting SCHED_FIFO priority ? ( normal or GDB execution )

前端 未结 3 1610
清歌不尽
清歌不尽 2021-01-24 01:08

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

3条回答
  •  一个人的身影
    2021-01-24 01:33

    There are a few things obviously wrong with your MCVE:

    1. You have a data race on b, i.e. undefined behavior, so anything can happen.

    2. 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.

提交回复
热议问题