prevent linux thread from being interrupted by scheduler

后端 未结 5 611
别那么骄傲
别那么骄傲 2020-12-01 10:49

How do you tell the thread scheduler in linux to not interrupt your thread for any reason? I am programming in user mode. Does simply locking a mutex acomplish this? I wa

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 11:30

    Look into real time scheduling under Linux. I've never done it, but if you indeed do NEED this this is as close as you can get in user application code.

    What you seem to be scared of isn't really that big of a deal though. You can't stop the kernel from interrupting your programs for real interrupts or of a higher priority task wants to run, but with regular scheduling the kernel does uses it's own computed priority value which pretty much handles most of what you are worried about. If thread A is holding resource X exclusively (X could be a lock) and thread B is waiting on resource X to become available then A's effective priority will be at least as high as B's priority. It also takes into account if a process is using up lots of cpu or if it is spending lots of time sleeping to compute the priority. Of course, the nice value goes in there too.

提交回复
热议问题