Questions tagged [reentrancy]

Reentrancy usually refers to subroutines, functions, methods and mutexes. A subroutine is considered reentrant if it can be safely called before a previous call has completed.

To be reentrant a subroutine, function, method etc must:

  • hold no static (or global) non-constant data
  • not return the address to static (or global) non-constant data
  • work only on the data provided to it by the caller
  • not rely on locks to singleton resources

A reentrant mutex's lock can be acquired multiple times by the same thread. However, the lock must be released the same number of times or else other threads will be unable to acquire the lock. It has some similarities to a counting semaphore. More info here: Reentrant mutex

See also

214 questions
5
votes
2 answers

Reentrant lock - Java concurrency in practice

Here is some sample code for reentrant locking from 'Java concurrency in practice': class Widget { public synchronized void doSomething() { System.out.println(toString() + ": calling superclass doSomething"); } } class LoggingWidget extends…
sotn
  • 1,833
  • 5
  • 35
  • 65
5
votes
4 answers

How to convince my co-worker the linux kernel code is re-entrant?

Yeah I know ... Some people are sometimes hard to convince of what sounds natural to the rest of us, an I need your help right now SO community (or I'll go postal soon ..) One of my co-worker is convinced the linux kernel code is not re-entrant as…
yves Baumes
  • 8,836
  • 7
  • 45
  • 74
5
votes
2 answers

Call a non-reentrant native shared library from multiple Java threads

I have some Java code that is calling some native code, originally written in Fortran, using JNA. (It's a numerical library, and lots of math people do their coding in Fortran.) It is compiled to a .so library, see below: Fortran:…
Andrew Mao
  • 35,740
  • 23
  • 143
  • 224
5
votes
1 answer

Dart: Is using a zero duration timer the supported way of deferring work to the event loop

I discovered by experimenting that creating a timer with a duration of 0 allows me to defer work into the event queue. I really like this feature, because it allows avoiding a lot of nasty reentrancy issues. Is this intentional functionality that…
Jim Belton
  • 231
  • 2
  • 8
4
votes
4 answers

Regarding multiple lock attempts, using java.concurrent.ReentrantLock

I've noticed that the following code block : final Lock s = new ReentrantLock(); for(int i = 0 ; i < 1000 ; i++) { s.lock(); System.out.println(i+" :" +s.tryLock()+" "); } Prints : 0 :true 1 :true 2 :true 3 :true…
jayunit100
  • 17,388
  • 22
  • 92
  • 167
4
votes
2 answers

When is function reverted?

so because of reentrancy attacks I'm structuring my function to not get hacked. So first updating mappings and so on and then sending the payment. My question is what if the payment fails to go through. Will entire function be reverted of just the…
Kuly14
  • 496
  • 3
  • 12
4
votes
2 answers

Deduce if a program is going to use threads

Thread-safe or thread-compatible code is good. However there are cases in which one could implement things differently (more simply or more efficiently) if one knows that the program will not be using threads. For example, I once heard that things…
alfC
  • 14,261
  • 4
  • 67
  • 118
4
votes
2 answers

Is puts reentrant?

Is int puts(const char*); re-entrant? Can I safely put it into a signal handler?
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
4
votes
1 answer

Detect the same goroutine calling sync.Mutex.Lock() twice in a row

This code (a single threaded program) will never work: func TestDoubleLockPanics(t *testing.T) { var mu sync.Mutex mu.Lock() mu.Lock() } However, when I run this test, there's no panic. The race detector does not print out a data race.…
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
4
votes
1 answer

Python: How to create a concurrent-safe reentrant context manager which is different in every context

I want to have an object conManager that is a reentrant context manager instance such that whenever I enter and exit its context it will print a number, but the number must be one higher than the number of the previus context (starting at 0).…
bentheiii
  • 451
  • 3
  • 15
4
votes
1 answer

Thread safe, reentrant, async-signal safe putenv

I apologise in advance for what will be a bit of a code dump, I've trimmed as much unimportant code as possible: // Global vars / mutex stuff extern char **environ; pthread_mutex_t env_mutex = PTHREAD_MUTEX_INITIALIZER; int putenv_r(char…
Daniel Porteous
  • 5,536
  • 3
  • 25
  • 44
4
votes
3 answers

Simple in-memory message queue

Our existing implementation of domain events limits (by blocking) publishing to one thread at a time to avoid reentrant calls to handlers: public interface IDomainEvent {} // Marker interface public class Dispatcher : IDisposable { private…
TrueWill
  • 25,132
  • 10
  • 101
  • 150
4
votes
2 answers

Monitors and re-entrancy (clarifies difference between re-entrant code and re-entrant lock)

Reading on locks in C#. I see that being able to acquire lock on same object multiple times is said to be possible because Monitors are re-entrant. The definition of re-entrant code as defined in wikipedia does not seem to fit well in this context.…
Aadith Ramia
  • 10,005
  • 19
  • 67
  • 86
4
votes
1 answer

Is std::atomic signal-safe?

I am working on a Linux app, which needs to be able to handle large bursts of signals. Although the signal handlers will run fast (I plan at most some thousands of cpu cycles), the signals will come in big bursts, and ideally I would completely…
peterh
  • 11,875
  • 18
  • 85
  • 108
4
votes
3 answers

Are Google Apps scripts reentrant?

"Reentrant" may not be the right term, but I think it is close. If I share a script with another user and we both execute it at the same time do we over-write each others variables?, or do the two executions happen in entirely distinct memory…
Martin Bramwell
  • 2,003
  • 2
  • 19
  • 35