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
15
votes
1 answer

Is the Scala compiler reentrant?

For a multi-player programming game, I'm working on a background compilation server for Scala that supports compilation of multiple, independent source trees submitted by the players. I succeeded in running fast, sequential compilations without…
14
votes
2 answers

What is a re-entrant parser?

Can someone explain this to me? In particular the difference between: http://github.com/whymirror/greg and http://piumarta.com/software/peg/ The former being a re-entrant version of the later.
cloudhead
  • 15,253
  • 6
  • 42
  • 37
12
votes
4 answers

Simplest way to make a whole method thread-safe?

There seems to be a lot to learn about multithreaded programming and it's all a bit intimidating. For my current needs, I just want to protect against a method being called again from another thread before it finishes, and my question is: Is this…
Igby Largeman
  • 16,495
  • 3
  • 60
  • 86
12
votes
5 answers

Is there a way to flag the use of non-reentrant C library calls?

I'm working on a project that's heavily multi-threaded, and was wondering if there's a way to have the compiler flag the use of non-reentrant calls to the C library (e.g. strtok intsead of strtok_r)? If not, is there a list of calls that are…
Ravi
  • 3,718
  • 7
  • 39
  • 57
12
votes
3 answers

Threading and static methods in C#

Here is a meaningless extension method as an example: public static class MyExtensions { public static int MyExtensionMethod(this MyType e) { int x = 1; x = 2; return x } } Say a thread of execution completes…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
11
votes
2 answers

malloc() is non-reentrant but thread-safe?

Possible Duplicate: Malloc thread-safe? I am not a bit confused while I am reading "The Linux Programming Interface". From the book it says that malloc is non-reentrant since it manipulates the global linked list data structure but is made…
kai
  • 1,141
  • 3
  • 15
  • 25
11
votes
1 answer

Reentrancy in JavaScript

I would like to improve my understanding of the word reentrant. Is this function reentrant? function* foo() { yield 1; yield 2; } And this one? function foo() { return 1; } And this one? var x = 0; function foo() { return x++; } And this…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
11
votes
1 answer

Is the main() function re-entrant?

I heard that in C, main() is reentrant, while in C++ is not. Is this true? What is the scenario of re-entering the main() function?
Deqing
  • 14,098
  • 15
  • 84
  • 131
11
votes
5 answers

Reentrant locking

A bit of help please, consider the bit of code below. public class Widget { public synchronized void doSomething() { ... } } public class LoggingWidget extends Widget { public synchronized void doSomething() { …
CaptainHastings
  • 1,557
  • 1
  • 15
  • 32
10
votes
3 answers

Is C++'s new operator reentrant (or async-safe)?

The background is in this question of mine. Put shortly, I have to fork in a multithreaded C++ program, so I'd like to figure out how much I can do when restricted to reentrant functions only, and one of the most essential things is dynamic…
xiaq
  • 764
  • 1
  • 6
  • 13
9
votes
1 answer

Writing re-entrant lexer with Flex

I'm newbie to flex. I'm trying to write a simple re-entrant lexer/scanner with flex. The lexer definition goes below. I get stuck with compilation errors as shown below (yyg issue): reentrant.l: /* Definitions */ digit [0-9] letter …
Viet
  • 17,944
  • 33
  • 103
  • 135
8
votes
2 answers

What is the difference between thread-aware and thread-safe?

What is the difference between thread-awareness and thread-safety?
8
votes
4 answers

Reentrant lock and deadlock with Java

Can someone explain to me how Reentrant lock and deadlock relate to each other with Java code (pseudo) example?
MatBanik
  • 26,356
  • 39
  • 116
  • 178
8
votes
2 answers

Problems with reentrant Flex and Bison

I'm learning how to use reentrant Bison and Flex together. I already got a simple calculator working without the reentrant capability. However when I activated the reentrant feature and made the necessary modifications, I couldn't get this to work.…
Fabricio
  • 343
  • 1
  • 5
  • 11
8
votes
9 answers

Can I add an attribute to a function to prevent reentry?

At the moment, I have some functions which look like this: private bool inFunction1 = false; public void function1() { if (inFunction1) return; inFunction1 = true; // do stuff which might cause function1 to get called ... …
Simon
  • 25,468
  • 44
  • 152
  • 266
1
2
3
14 15