开发者

What does the term "interrupt safe" mean?

开发者 https://www.devze.com 2023-03-16 06:04 出处:网络
I come across this开发者_StackOverflow社区 term every now and then. And now I really need a clear explanation as I wish to use some MPI routines that

I come across this开发者_StackOverflow社区 term every now and then. And now I really need a clear explanation as I wish to use some MPI routines that are said not to be interrupt-safe.


I believe it's another wording for reentrant. If a function is reentrant it can be interrupted in the middle and called again.

For example:

void function()
{
    lock(mtx);
    /* code ... */
    unlock(mtx);
}

This function can clearly be called by different threads (the mutex will protect the code inside). But if a signal arrives after lock(mtx) and the function is called again it will deadlock. So it's not interrupt-safe.


Code that is safe from concurrent access from an interrupt is said to be interrupt-safe.

Consider a situation that your process is in critical section and an asynchronous event comes and interrupts your process to access the same shared resource that process was accessing before preemption.

It is a major bug if an interrupt occurs in the middle of code that is manipulating a resource and the interrupt handler can access the same resource. Locking can save you!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号