English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

int z; /* 16-bit global */
void maximum(int w, int x, int y)
{
z=2;
if(x>z) z=x;
if(y>z) z=y;
}

I know this program is non-reentrant but why? Also, how would I make it reentrant?

2007-02-22 12:04:02 · 1 answers · asked by Kyle 1 in Computers & Internet Software

1 answers

You modify a global variable. That can't be called simultaneously by multiple processes. In general you can only work on data passed to you.

Try something like:

int maximum(int w, int x, int y)
{
if (w > x)
{
if(w > y)
return w;
else return y;
}
else if (x > y)
return x;
else return y;
}

2007-02-24 07:57:45 · answer #1 · answered by John Mahowald 5 · 0 0

fedest.com, questions and answers