What does the term "interrupt safe" mean?
Asked Answered
B

2

7

I come across this 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.

Bejarano answered 30/6, 2011 at 13:43 Comment(1)
The typical quote in the MPI manual is (repeatedly) "This routine is thread-safe. This means that this routine may be safely used by multiple threads without the need for any user-provided thread locks. However, the routine is not interrupt safe. Typically, this is due to the use of memory allocation routines such as malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. " (for example here: mpich.org/static/docs/v3.3/www3/MPI_Type_dup.html). I am also trying to find what it means.Epitasis
J
8

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.

Jacquline answered 30/6, 2011 at 13:59 Comment(2)
@RestlessC0bra Your example implicitly assumes recursive locks, considered by some to be bad.Jacquline
@RestlessC0bra Let's say a thread acquires the mutex. Then the same thread handles a signal and somehow starts executing the function all over again (this is all quite usual). If the locks isn't recursive (and it shouldn't be) the one and only thread is deadlocked.Jacquline
G
2

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!

Gussiegussman answered 11/4, 2013 at 2:58 Comment(1)
The complete quote the OP is referring to is "Thread and Interrupt Safety This routine is thread-safe. This means that this routine may be safely used by multiple threads without the need for any user-provided thread locks. However, the routine is not interrupt safe. Typically, this is due to the use of memory allocation routines such as malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. " (for example here: mpich.org/static/docs/v3.3/www3/MPI_Type_dup.html). It says specifically that (thread) locks are not necessary.Epitasis

© 2022 - 2024 — McMap. All rights reserved.