How can I prevent my thread from being prevented in user mode

I have a simple piece of deterministic work that requires only thirteen machine instructions. Since the first instruction accepts a homemade spinlock semaphore, and the last command releases it, I am sure of safety from all other threads working on other kernels when they try to take and give the same semaphore.

The problem arises when a thread interrupts a thread containing a semaphore before it can complete its “critical section”. In the worst case, an interrupt kills the thread by holding the semaphore, or, as it may happen, one of the threads that usually compete for the semaphore branches produces code that can generate an interrupt that causes a dead end.

I have no way of synchronizing with these other threads when they enter those parts of the code that I cannot control. I think I need to disable interrupts, as I did in my old VxWorks days when I was working in kernel mode. There are always thirteen instructions, and I am always completely safe if I can follow all thirteen instructions before I have to interrupt. Oh, and this is all my own internal data, others that there is nothing in the home semaphore that blocks something else.

I read a few answers that I think are close. Most of them involve calls to the critical section in the Windows API (the wrong OS, but possibly the right concept). Most of the wrong decisions suggest that I can force all abusive threads to use the mutex that I create using the pthread libraries.

I need this solution in C / C ++ for Linux and Solaris.

Johnny Crush question is very close prevent linux thread from interrupting scheduler

KermitG also Can I prevent pthread for a Linux user in critical code?

Thank you for your attention.

+5
source share
1 answer

. ( ) , .

- , - - .

: .

+3

All Articles