相关疑难解决方法(0)

不能在C++中激发优先级倒置

我试图在一个小的C++程序上激发优先级倒置以进行演示,但我不能:持有互斥锁的低优先级线程没有被抢占并继续在关键部分运行.这就是我正在做的事情:

// let's declare a global mutex
pthread_mutex_t my_mutex;
  ...

int main(int argc, char **argv) {
  ...
  pthread_t normal_thread;
  pthread_t prio_thread;

  pthread_mutexattr_t attr;
  pthread_mutexattr_init (&attr);
  pthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_NONE);  // ! None !
  pthread_mutex_init(&my_mutex, &attr);

  // create first normal thread (L):
  pthread_create(&normal_thread, NULL, the_locking_start_routine, NULL);

  // just to help the normal thread enter in the critical section
  sleep(2);

  // now will launch:
  // * (M) several CPU intensive SCHED_FIFO threads with priority < 99
  // …
Run Code Online (Sandbox Code Playgroud)

c++ mutex pthreads real-time thread-priority

3
推荐指数
1
解决办法
3096
查看次数

标签 统计

c++ ×1

mutex ×1

pthreads ×1

real-time ×1

thread-priority ×1