I'm reading Stallings' "Operating Systems Internals and Design Principles", and in the chapter about concurrency and mutual exclusion it reads:
In a uniprocessor system, concurrent processes cannot have overlapped execution; they can only be interleaved. Furthermore, a process will continue to run until it invokes an OS service or until it is interrupted.Therefore, to guarantee mutual exclusion, it is sufficient to prevent a process from being interrupted. This capability can be provided in the form of primitives defined by the OS kernel for disabling and enabling interrupts.
I've found this post in SO that seems to address this question, but the OP doesn't give specifics about the type of interrupt he wants to stop, and the post is dead without ever getting an accepted answer (besides the OP deleted the profile), so I was hoping to get to the bottom of this here. Assuming that I want the CPU fully dedicated to my code (this is only in theory, I know this is very dangereous), how would I be able to achieve this with Java?
The best solution I have found in practice is to isolate the CPU i.e. add isolcpus= to you linux boot, configure IRQ Balance to not use it and, bind specific threads to these isolated CPUs. This reduces jitter to around 10 - 40 micro-seconds. This is a library I wrote to support this https://github.com/OpenHFT/Java-Thread-Affinity It is often used in low latency trading systems to minimize jitter.
Note: there are non-maskable interrupts which cannot be turned off this way, and I suspect it would be unsafe to do so.
You can use a machine code instruction to disable interrupts and enable them again, however you would have to be a privileged user and almost certainly things in the OS would break if you did this for any length of time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With