Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Reentrancy (computing)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Further examples== In the following code, neither <code>f</code> nor <code>g</code> functions is reentrant. <syntaxhighlight lang="c"> int v = 1; int f() { v += 2; return v; } int g() { return f() + 2; } </syntaxhighlight> In the above, {{code|f()}} depends on a non-constant global variable {{code|v}}; thus, if {{code|f()}} is interrupted during execution by an ISR which modifies {{code|v}}, then reentry into {{code|f()}} will return the wrong value of {{code|v}}. The value of {{code|v}} and, therefore, the return value of {{code|f}}, cannot be predicted with confidence: they will vary depending on whether an interrupt modified {{code|v}} during {{code|f}}'s execution. Hence, {{code|f}} is not reentrant. Neither is {{code|g}}, because it calls {{code|f}}, which is not reentrant. These slightly altered versions ''are'' reentrant: <syntaxhighlight lang="c"> int f(int i) { return i + 2; } int g(int i) { return f(i) + 2; } </syntaxhighlight> In the following, the function is thread-safe, but not (necessarily) reentrant: <syntaxhighlight lang="c"> int function() { mutex_lock(); // ... // function body // ... mutex_unlock(); } </syntaxhighlight> In the above, {{code|function()}} can be called by different threads without any problem. But, if the function is used in a reentrant interrupt handler and a second interrupt arises inside the function, the second routine will hang forever. As interrupt servicing can disable other interrupts, the whole system could suffer.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)