Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable interrupt in a C program in linux

I am writing a simple code in c on a Linux(A13-OLinuXino-MICRO) with A13 processor. I am using gcc compiler if that's important. Let's say I have a simple loop that is just counting from 1 to 100 and I want to have as less as possible interruption in this loop. I assume the best that I can do is disabling interrupts(even the timer interrupt if possible) and enabling it after the loop. I have multiple places in my program that I need to enforce this. Can anybody help me with a simple C code that a loop is protected from interruption...something that I can compile and run on my platform?

EDIT: Kernel thread might be an answer. How can I run something with kernel privilege? I see people talk about disable_local_interrupt() but I don't know how to use it.

EDIT: This is the actual problem that I am trying to solve. I need to run my applications in a interrupt-free environment.

EDIT: Yes I am sure that Linux is what I need to use and I know that interrupts are important for OS and that's why I don't want to disable them forever. I just want to enforce no-interrupt for a fraction of second on OS when I am running this. Also, There is no main problem that I need to solve, this is "the problem" that I need to solve, so stop asking why I want to do this.

like image 999
Nhome Avatar asked Jan 25 '17 18:01

Nhome


1 Answers

Userspace cannot disable or enable interrupts.

like image 158
doron Avatar answered Sep 28 '22 00:09

doron