What do you exactly mean by Reentrant function?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I guess this should be right place to ask this question.

What I know is at the higher level where the variables in a function
should not be shared so that they dont get corrupted when the function
is interrupted. I wanted a much more clear and basic view and a much
more detiled explanation of the reentrancy concept.

Also I've heard people use reentrant function and reentrant code
differently. Is there any difference between them? I believe they
should be same.

Also can somebody throw light on the  DO's and DON'Ts for embedded
system programming in C. Well I understand that the list might be long
and not necessarily exhaustive, but anything as long as it makes sense
:) would be appreciated.

Thanx in advance.
--Taran


Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it

As one coming from the Forth stables I consider that the terms "re-entrant
code" and "re-entrant function" are synonymous. As for the variables, if
you consider that they need to operate just like a stack then you should
get an idea of how such functions can be made efficient. Of course, it is
something Forthists hardly think about as Forth is built around virtual or
real stack machines.
 
Quoted text here. Click to load it

Start with a copy of the MISRA C Guidelines and tune your Lint-alike tool
to enforce as much of that as possible. Then it is mostly review and test
frequently and thoroughly and keep your configuration management tight and
well-audited.

Of course, you could always consider coming over to Forth ;>

--
********************************************************************
We've slightly trimmed the long signature. Click to see the full one.
Re: What do you exactly mean by Reentrant function?
Quoted text here. Click to load it


Re-entrant functions are those that can be called by themselves or may
be called by a function they call. thus there is more than one instance
of the function running at any one time.

What is the processor? On many 8 bit systems the compilers do not do re-
entrancy unless you explicitly tell them to. This is to save space. Both
in the stack and other memory. This is because you need a duplicate set
of data for themas well as stack space. In large systems it does not
matter.

Quoted text here. Click to load it

Probably they are the same...  I would have thought so but.. never say
die. There is always some one turning up some highly implausible code
that no one in their right mind would have in a real system.

Quoted text here. Click to load it

Have a look at www.phaedsys.org  (or www.phaedsys.demon.co.uk I am inthe
middle of re-siting my web site)  You need the QuEST series of papers. A
bit long in the tooth and under a re-write but basically they are OK.

Regards
   chris

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England    /\/\/\/\/\
/\/\/ snipped-for-privacy@phaedsys.org       www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/




Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it

They are also functions that can be called from multiple threads.  The
situation being that it can interrupted in mid-execution in one
thread, and be called from another.  Both threads should still get
their expected results when their respective calls to the function
complete.

Rufus



Re: What do you exactly mean by Reentrant function?
There are two things: reenterable code and reentrant code.

A reentrant function is one that can be called from multiple threads
simultaneously.  Specifically,
the execution of the function can be interrupted, and it can be called again
(e.g.) from another
thread, without affecting the operation of the function for either thread.
Reentrant functions are
also reenterable.

A reenterable function is one which can be called more than one time and produce
the same results
from the same data.  This definition has to be bent for those functions which
are *supposed* to
return a result based on history (such as returning the number of times it has
been called).

A reenterable function that is not reentrant is one that requires initialization
of static or
global data.

A non-reenterable function is one that, for example, doesn't (properly)
initialize itself (relying
on static start-up values), or that destroys its initial data.


--
#include <standard.disclaimer>
 _
Kevin D Quitt  USA 91387-4454         96.37% of all statistics are made up
We've slightly trimmed the long signature. Click to see the full one.
Re: What do you exactly mean by Reentrant function?
Quoted text here. Click to load it
simultaneously.  Specifically,
Quoted text here. Click to load it
called again (e.g.) from another
Quoted text here. Click to load it
thread.  Reentrant functions are
Quoted text here. Click to load it
and produce the same results
Quoted text here. Click to load it
functions which are *supposed* to
Quoted text here. Click to load it
times it has been called).
Quoted text here. Click to load it
initialization of static or
Quoted text here. Click to load it

Till now I assumed that reentrant and reentrable functions are same.

This is confusing. Based on your definition of re-entrable function:

-- All functions which use non static local variables and with
arguments passed by value would produce the same result.
-- All functions which use static variables, which not constitutes
history, are reentrable.
-- If they use pointers, then they also become part of history and are
again reentrable.

I can't figure out of a non-reentrable function.

Quoted text here. Click to load it
(properly) initialize itself (relying
Quoted text here. Click to load it

Can you please give an example.

[snip]

Thanks in advance
--
Taran


Re: What do you exactly mean by Reentrant function?
Quoted text here. Click to load it
simultaneously.  Specifically,
Quoted text here. Click to load it
called again (e.g.) from another
Quoted text here. Click to load it
thread.  Reentrant functions are
Quoted text here. Click to load it
and produce the same results
Quoted text here. Click to load it
functions which are *supposed* to
Quoted text here. Click to load it
times it has been called).
Quoted text here. Click to load it
initialization of static or
Quoted text here. Click to load it

Till now I assumed that reentrant and reentrable functions are same.

This is confusing. Based on your definition of re-entrable function:

-- All functions which use non static local variables and with
arguments passed by value would produce the same result.
-- All functions which use static variables, which not constitutes
history, are reentrable.
-- If they use pointers, then they also become part of history and are
again reentrable.

I can't figure out of a non-reentrable function

Quoted text here. Click to load it
(properly) initialize itself (relying
Quoted text here. Click to load it

Can you please give an example.

[snip]

Thanks in advance
--
Taran


Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it

Well, in C, you have to go out of your way to generate a non-reenterable
function.  In assembly,
it's a lot easier: self-modifying code that is designed to work once, and that
modifies an
instruction by incrementing it.  A disk-use analyzer that only reads the usage
bitmap in from the
disk if its internal buffer is all zeroes.

Good programmers have a very hard time writing non-reenterable code.  Only
'clever' programmers
have an easy time of it.


--
#include <standard.disclaimer>
 _
Kevin D Quitt  USA 91387-4454         96.37% of all statistics are made up
We've slightly trimmed the long signature. Click to see the full one.
Re: What do you exactly mean by Reentrant function?
Quoted text here. Click to load it
non-reenterable function.

By your definition, a function implementing a state diagram
would be non reenterable, is that right ?


Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it

Clearly, my definition is suspect.  How about:

A function that operates correctly when asynchronously reentered is 'reentrant'.

A function that operates correctly when serially reentered is 'reenterable'.


--
#include <standard.disclaimer>
 _
Kevin D Quitt  USA 91387-4454         96.37% of all statistics are made up
We've slightly trimmed the long signature. Click to see the full one.
Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it
'reentrant'.
'reenterable'.

When you say serially, I suppose you mean that a call occurs only
when all others calls have returned.

Consider a function that is called whenever an event occurs, serially
and that implements a state diagram. Presumably, the state will change
at each function call, and a successive call with the same arguments
will not yield the same result. Well, the function still operates
correctly, but I don't see your point.


Re: What do you exactly mean by Reentrant function?


Quoted text here. Click to load it

In oder to save its state between calls this function must use static or
global variables to save its state. It cannot therefore be re-entrant.

Ian

Re: What do you exactly mean by Reentrant function?
Quoted text here. Click to load it
serially
or
re-entrant.

The point was not about re-entrant functions but about re-enterable
functions according to the terminology introduced here:

Quoted text here. Click to load it

What does mean data here?

Quoted text here. Click to load it

Presumably not history

The clarification,

Quoted text here. Click to load it

is still not clear for me. Clearly the points 1 and 3 are
contradictory. *Correctly* would require a more precise
definition.


Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it

No idea. The definition of re-enterable and its differentiation from
re-entrant seems not to have been made. I thought your original question
was about re-entrant functions?

Ian

Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it
static
question

Kevin D Quit wrote above

Quoted text here. Click to load it


Ok



What is not clear is what data represent. Arguments, globals ?

If *all* data are the same, it is clear that the result will be
the same if the code is not altered. I must miss something here.


Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it

It is not :)  File operations are not guaranteed to give the same result
if, for example, you  are reading a file that has been unexpectedly
deleted between reads.

IMHO, the very definition of "reenterable" as opposed to "reentrant" is
far-fetched.

   Vadim Borshchev

Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it
result

Well, yes but some *data* has changed then, the file itself.
This is an event that does not depend presumably on the properties
of the function.

I think the discussion leads to nowhere, hence

Quoted text here. Click to load it
is

I agree


Re: What do you exactly mean by Reentrant function?

Quoted text here. Click to load it

Me too, it does not make sense.

Ian

Re: What do you exactly mean by Reentrant function?
On Thu, 14 Apr 2005 08:37:48 -0700, the renowned Kevin D. Quitt

Quoted text here. Click to load it
function.

You mean, like using a standard library function?


Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.
Re: What do you exactly mean by Reentrant function?
On Thu, 14 Apr 2005 12:15:20 -0400, Spehro Pefhany


Quoted text here. Click to load it
function.
Quoted text here. Click to load it

The standard C library functions are re-enterable.

If a thread shares all the same environment as its part, and a task has its own
environment, then
the for tasks, the C library is re-entrant for tasks, but not for threads.
There only needs to be
one copy of the C library in memory to accommodate all tasks.


--
#include <standard.disclaimer>
 _
Kevin D Quitt  USA 91387-4454         96.37% of all statistics are made up
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline