Can I prevent a Linux user space pthread yielding in critical code?

前端 未结 3 1969
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 07:34

I am working on an user space app for an embedded Linux project using the 2.6.24.3 kernel. My app passes data between two file nodes by creating 2 pthreads that each sleep

3条回答
  •  生来不讨喜
    2020-12-18 08:13

    You can use the sched_setscheduler() system call to temporarily set the thread's scheduling policy to SCHED_FIFO, then set it back again. From the sched_setscheduler() man page:

    A SCHED_FIFO process runs until either it is blocked by an I/O request, it is preempted by a higher priority process, or it calls sched_yield(2).

    (In this context, "process" actually means "thread").

    However, this is quite a suspicious requirement. What is the problem you are hoping to solve? If you are just trying to protect your linked list of completion handlers from concurrent access, then an ordinary mutex is the way to go. Have the completion thread lock the mutex, remove the list item, unlock the mutex, then call the completion handler.

提交回复
热议问题