Re: Reentrancy
- From: "Kürşat" <kursattheking@xxxxxxxxx>
- Date: Fri, 10 Apr 2009 00:43:54 +0300
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:uYHFlaSuJHA.1240@xxxxxxxxxxxxxxxxxxxxxxx
Krat <kursattheking@xxxxxxxxx> wrote:
The wikipedia
article(http://en.wikipedia.org/wiki/Reentrant_(subroutine)) that
defines "reentrant" gives 6 rules to write reentrant code. According
to the definition a function like this is reentrant :
char reentrant_func (char * ptr)
{
return *(ptr + 2);
}
CALL-2
char * buf = 0;
int main ()
{
buf = (char * ) malloc (256);
strcpy (buf, "Reentrant");
char c = reentrant_func (buf);
}
In call-2 we supplied a pointer to a global data so the function call
may not be reentrant.
A function can be reentrant or not. It's meaningless to say that a
particular function call is reentrant or not - you can't make the same
call twice.
I actually don't claim that a function call can be reentrant, I just try to
grasp this :
if a function that manipulates a global variable is non-reentrant then can
we be sure that a function which indirectly refers to a global variable via
a pointer is reentrant? The article explains that if a function that uses a
global variable is non-reentrant because value of the varible can be changed
by another thread. The global variable referred by the pointer can be
changed by another thread too. So I think the definition in the article is
short, it should add another condition that states "a function that takes a
reference to a global resource is non-reentrant". According to this new
condition, if a caller passes a pointer to a local variable then the
function will be reentrant but otherwise the function will be non-reentrant.
That is what I try to expose.
In any case, in what sense is the situation you show non-reentrant? Does
the function not successfully return the third character of the passed-in
buffer? Will it not continue to do so even if called concurrently?
It will work in either way but it it refers to a global variable then the
variable is subject to be manipulated by another thread.
So I think "not only functions but also
function calls should be reentrant".
Define "reentrant function call". I'm not familiar with the term.
--
"Reentrant function call" does not exist. I invent the term to explain my
point.
May be I does not completely grasp reentrancy and its relation with
thread-safety. I will be happy if you explain briefly.
.
- Follow-Ups:
- Re: Reentrancy
- From: Igor Tandetnik
- Re: Reentrancy
- References:
- Reentrancy
- From: Kürşat
- Re: Reentrancy
- From: Igor Tandetnik
- Reentrancy
- Prev by Date: Re: Handling ( Copying) COM Interface reference
- Next by Date: Re: Reentrancy
- Previous by thread: Re: Reentrancy
- Next by thread: Re: Reentrancy
- Index(es):
Relevant Pages
|