473,756 Members | 6,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reentrant functions

what are reentrant functions? What are the characteristics of a reentrant code ?
what things should be kept in mind while writing a reentrant code ?
Nov 14 '05 #1
6 11046
"junky_fell ow" <ju**********@y ahoo.co.in> wrote in message
news:8c******** *************** ***@posting.goo gle.com...
what are reentrant functions? What are the characteristics of a reentrant
code ?
what things should be kept in mind while writing a reentrant code ?


Smells of homework, but I'd like to know too, not for homework :)
Nov 14 '05 #2
"Kieran Simkin" <ki****@digit al-crocus.com> wrote in message
news:4G******** ****@newsfe5-gui.ntli.net...
"junky_fell ow" <ju**********@y ahoo.co.in> wrote in message
news:8c******** *************** ***@posting.goo gle.com...
what are reentrant functions? What are the characteristics of a reentrant
code ?
what things should be kept in mind while writing a reentrant code ?


Smells of homework, but I'd like to know too, not for homework :)


Obviously homework, the same as the OP's other question
about position independent code.

Reentrancy is a characteristic of a program in memory
that does not modify itself in any way. Thus, multiple
threads (units of work) can concurrently execute the code
without interferring with each other. Reentrant programs
can be shared by multiple threads and by multiple processes,
because the program itself is essentially "read only".

Non-reentrancy is a characteristic of a program in memory
that is modifying itself as it executes. Other threads,
being dispatched via time slicing algorithm, will likely
see the program in an inconsistent state (partially modified
by the other thread). A non-reentrant program cannot be shared
multiple threads or processes. Each thread or process
that wants to run the program must load its own copy of
the program.

Please let me know how the instructor graded my answers.
--
----------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!


Nov 14 '05 #3


xarax wrote:
"Kieran Simkin" <ki****@digit al-crocus.com> wrote in message
news:4G******** ****@newsfe5-gui.ntli.net...
"junky_fell ow" <ju**********@y ahoo.co.in> wrote in message
news:8c******** *************** ***@posting.goo gle.com...
what are reentrant functions? What are the characteristics of a reentrant
code ?
what things should be kept in mind while writing a reentrant code ?


Smells of homework, but I'd like to know too, not for homework :)


Obviously homework, the same as the OP's other question
about position independent code.

Reentrancy is a characteristic of a program in memory
that does not modify itself in any way. Thus, multiple
threads (units of work) can concurrently execute the code
without interferring with each other. Reentrant programs
can be shared by multiple threads and by multiple processes,
because the program itself is essentially "read only".

Non-reentrancy is a characteristic of a program in memory
that is modifying itself as it executes. Other threads,
being dispatched via time slicing algorithm, will likely
see the program in an inconsistent state (partially modified
by the other thread). A non-reentrant program cannot be shared
multiple threads or processes. Each thread or process
that wants to run the program must load its own copy of
the program.

Please let me know how the instructor graded my answers.

--
----------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!


Huh???
the question was non-reentrant functions not non-reentrant programs.

non-reentrant function either call themselves or can be call from interrupts
other threads, task ect.
Normally you do not have to do anything to the function. But, the data it uses
has limitations.
You can not have static variables in the function. You have to deal with access
to globals.
Google "The Tower of Hanoi Puzzle" it is the usual text book example of
non-reentrantcy.

Nov 14 '05 #4
Neil Kurzman <ns*@mail.asb.c om> wrote:
xarax wrote:
"Kieran Simkin" <ki****@digit al-crocus.com> wrote:
"junky_fell ow" <ju**********@y ahoo.co.in> wrote:
> what are reentrant functions? What are the characteristics of a
> reentrant code ?
> what things should be kept in mind while writing a reentrant code?

Smells of homework, but I'd like to know too, not for homework :)


Obviously homework, the same as the OP's other question
about position independent code.

Reentrancy is a characteristic of a program in memory
that does not modify itself in any way. Thus, multiple
threads (units of work) can concurrently execute the code
without interferring with each other. [...]


Huh???
the question was non-reentrant functions not non-reentrant programs.
non-reentrant function either call themselves or can be call from interrupts
other threads, task ect. Normally you do not have to do anything to the
function. But, the data it uses has limitations. You can not have static
variables in the function. You have to deal with access to globals. [...]


Ok people, everyone just sit down.

A non-reentrant function is a function that cannot properly reenter.
That is, it cannot by called again while a previous instance is still
considered live (i.e., its been called but has not yet returned). Its
not just that its non-recursive -- it cannot call something which
calls something else, etc and eventually call itself again. While the
static variables with multithreading is an obvious example of
non-reentrant functions, there are far simpler ones as well (otherwise
the CLC keystone cops would be in here claiming this was off topic).

For example, suppose qsort() was implemented to choose a completely
random element from each partition with which to pivot. And in the
call back comparison function, in addition to comparing the two
values, you sometimes (chosen on a random basis) recursively called
qsort on some proper (i.e., not identical to the original) subset of
the list. If you think about it, its clear to see that the partitions
will not retain their expected properties and therefore this will not
sort properly. So in a sense qsort is not re-entrant under these
conditions.

Another simple example is nested parsing. Suppose that you want to
split out substrings from a string and pass them to a callback
function (like qsort calls out to a user defined comparison function).
As parameters to your function (lets call it simpleParse()) you might
pass the source string, the string of divider tokens, and a callback
function which gets called on each subset string. Its not hard to see
how to do with very simply with strtok(). So a simple thing you might
like to do is divide the contents of a text file into lines, then
divide the lines into words. So you would think you could so
something like simpleParse(src Text,"\r\n",lin es); where lines() would
basically call simpleParse(src Line," \v\f\t",word). But because of a
defect in the design of the strtok() C library function there is no
way to make it work (because a static referenced by strtok is tracking
a singular string that it is tokenizing.)

The main thing to watch out for with non-reentrant functions is that
nesting calls to itself don't cause it to overwrite some kind of
shared context from any pair of live instances. One class of
functions to worry about are those that store results in
statics/globals that are reused either in subsequent calls or through
calls that it makes itself (through function pointers or other
mechanism.) But the overwriting state need not be static/global -- it
can literally be a context passed in as a parameter as well.

But that isn't to say that if a function uses a static/global or
potentially shared parameter that it will necessarily be
non-reentrant. For example, if it completes all usage of the shared
resource before re-entering, then there is no risk of reentrancy
problems. There may be other combinations of conditions that prevents
a re-entered instance of a function from modifying a shared resource
that a parent instance is modifying. And of course some shared
resources may easily survive randomly ordered modifications regardless
of reentrancy (like a global statistics counter or something like
that).

<OT> Interrupt Service Routines are simplest example of an
asynchronous call that might have reentrancy issues. The problem is
that an ISR can be "pre-empted" with another ISR call to the same call
at any time during its execution. So for shared memory usage, the ISR
doesn't have a choice about when another reentrant call my come to use
that same shared memory. Proper solutions to this are way off topic
in CLC.

Preemtive multithreading of shared memory in essence have the same
problem except that its usually just categorized as "thread safety"
rather than "reentrancy safety". Again, proper solutions to this are
way off topic in CLC, nevertheless sometimes solutions require only
design considerations that can be implemented in ANSI/ISO C.</OT>

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
Nov 14 '05 #5
"Neil Kurzman" <ns*@mail.asb.c om> wrote in message
news:41******** *******@mail.as b.com...


xarax wrote:
"Kieran Simkin" <ki****@digit al-crocus.com> wrote in message
news:4G******** ****@newsfe5-gui.ntli.net...
"junky_fell ow" <ju**********@y ahoo.co.in> wrote in message
news:8c******** *************** ***@posting.goo gle.com...
> what are reentrant functions? What are the characteristics of a reentrant > code ?
> what things should be kept in mind while writing a reentrant code ?

Smells of homework, but I'd like to know too, not for homework :)
Obviously homework, the same as the OP's other question
about position independent code.

Reentrancy is a characteristic of a program in memory
that does not modify itself in any way. Thus, multiple
threads (units of work) can concurrently execute the code
without interferring with each other. Reentrant programs
can be shared by multiple threads and by multiple processes,
because the program itself is essentially "read only".

Non-reentrancy is a characteristic of a program in memory
that is modifying itself as it executes. Other threads,
being dispatched via time slicing algorithm, will likely
see the program in an inconsistent state (partially modified
by the other thread). A non-reentrant program cannot be shared
multiple threads or processes. Each thread or process
that wants to run the program must load its own copy of
the program.

Please let me know how the instructor graded my answers.


Huh???
the question was non-reentrant functions not non-reentrant programs.

non-reentrant function either call themselves or can be call from interrupts
other threads, task ect.


Non-sequitur. No such thing as reentrant/non-reentrant FUNCTION.

You confusing terminology; reentrant versus recursive. Two entirely
different concepts.
Normally you do not have to do anything to the function. But, the data it uses has limitations.
You can not have static variables in the function. You have to deal with access to globals.
Google "The Tower of Hanoi Puzzle" it is the usual text book example of
non-reentrantcy.


You are thinking recursive, rather than reentrant. These
terms mean entirely different concepts.
Nov 14 '05 #6
xarax wrote:
"Neil Kurzman" <ns*@mail.asb.c om> wrote in message
news:41******** *******@mail.as b.com...

xarax wrote:

"Kieran Simkin" <ki****@digit al-crocus.com> wrote in message
news:4G***** *******@newsfe5-gui.ntli.net...

"junky_fell ow" <ju**********@y ahoo.co.in> wrote in message
news:8c**** *************** *******@posting .google.com...

>what are reentrant functions? What are the characteristics of a
reentrant
code ?
>what things should be kept in mind while writing a reentrant code ?

Smells of homework, but I'd like to know too, not for homework :)

Obviously homework, the same as the OP's other question
about position independent code.

Reentrancy is a characteristic of a program in memory
that does not modify itself in any way. Thus, multiple
threads (units of work) can concurrently execute the code
without interferring with each other. Reentrant programs
can be shared by multiple threads and by multiple processes,
because the program itself is essentially "read only".

Non-reentrancy is a characteristic of a program in memory
that is modifying itself as it executes. Other threads,
being dispatched via time slicing algorithm, will likely
see the program in an inconsistent state (partially modified
by the other thread). A non-reentrant program cannot be shared
multiple threads or processes. Each thread or process
that wants to run the program must load its own copy of
the program.

Please let me know how the instructor graded my answers.


Huh???
the question was non-reentrant functions not non-reentrant programs.

non-reentrant function either call themselves or can be call from interrupts
other threads, task ect.


Non-sequitur. No such thing as reentrant/non-reentrant FUNCTION.

You confusing terminology; reentrant versus recursive. Two entirely
different concepts.


There is nothing wrong with that. Non-reentrant functions _can_ call
themselves, which is recursion, or been called by other threads,
interrupt handler and the like.
Normally you do not have to do anything to the function. But, the data it
uses has limitations.
You can not have static variables in the function. You have to deal with
access to globals.
Google "The Tower of Hanoi Puzzle" it is the usual text book example of
non-reentrantcy.


You are thinking recursive, rather than reentrant. These
terms mean entirely different concepts.


Please carefully read the replys, there is no misconeception in them.

\Steve

--

Steve Graegert {C/C++ && Java && .NET}
CSI Technology Group (StReG)
<graegerts(AT)c s(DOT)technolog ies(DOT)de>
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2846
by: TheOne | last post by:
Would anyone please point me to a list of reentrant GNU C/C++ library functions? I have searched a lot on the web for it but without any success. Man page of signal(2) has listed system calls (POSIX 1003.1-2003 list) which are safe(reentrant) but thats not sufficient for my purpose. Thanks in advance.
9
8299
by: TheOne | last post by:
Would anyone please point me to a list of reentrant C library functions? I want to know which C library functions are safe to use inside a signal handler across all platforms. Does GNU C library make few other functions reentrant on Linux platform? I have searched a lot on the web for it but without any success. Man page of signal(2) has listed system calls (POSIX 1003.1-2003 list) which are safe(reentrant) but thats not sufficient for...
17
3273
by: fmassei | last post by:
Dear all, I'm trying to put some old code in a portable, cross-platform library and I'm facing a big problem: is there a standard, platform- independent way to write a reentrant function that allocate dynamic memory? In other words: is it safe to use malloc() or free() in a thread-safe function? Thank you, Francesco
12
3500
by: Bit Byte | last post by:
I am modifying some legacy code, to make the functions reentrant. I use lots of global data (large nested structs) to pass data around quicky. The global structures are far too large (in size) for each of my functions to maintain copies. Any suggestions on the best way to write a reentrant version of my library? - bearing in mind that my global vars are mostly, pointers to *HUGE* structures.
0
9454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10028
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9707
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6533
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3804
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3352
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2664
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.