1

I want to know if there is a possibility for a function to be thread safe but not reentrant. In some websites, they say that it's not possible, whereas others say it is possible. Examples given by them who say that it's possible are not clear. So is it possible to have a function that's thread safe and not reentrant? Is there a clear example to prove this point?

  • refer this question http://stackoverflow.com/questions/856823/threadsafe-vs-re-entrant – Umesh Aawte Jun 28 '12 at 09:48
  • PRNG for Linux. Have a look at [link](http://stackoverflow.com/questions/7797664/what-is-the-most-correct-way-to-generate-random-numbers-in-c-with-pthread/31162121#31162121) – Dawid Szymański Jul 01 '15 at 13:51

1 Answers1

2

Example from this article: http://en.wikipedia.org/wiki/Reentrancy_%28computing%29

int function()
{
 mutex_lock();
 ...
 function body
 ...
 mutex_unlock();
}

If an interrupt interrupts this function and the interrupt handler calls this function the system will hang forever as the first function locked the mutex.

Calmarius
  • 18,570
  • 18
  • 110
  • 157