Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jun 2000 01:41:28 -0700
From:      Alfred Perlstein <bright@wintelcom.net>
To:        pirat <pirat@access.inet.co.th>
Cc:        questions@FreeBSD.ORG
Subject:   Re: reentrant code for Intel
Message-ID:  <20000618014128.A18462@fw.wintelcom.net>
In-Reply-To: <Pine.BSF.4.21.0006181453530.1776-100000@parwati.oaep.go.th>; from pirat@access.inet.co.th on Sun, Jun 18, 2000 at 03:20:03PM %2B0700
References:  <Pine.BSF.4.21.0006181453530.1776-100000@parwati.oaep.go.th>

next in thread | previous in thread | raw e-mail | index | archive | help
* pirat <pirat@access.inet.co.th> [000618 01:19] wrote:
> hi sirs,
> 
> many many years ago, i used to program lsi-11 and it was quite easy to
> code some thing in re-entrant fashion since lsi-11 had a hard ware stack
> register, R6.
> 
> as far as i know, intel does not have any hardware stack so that one can
> not write any co routine. i may be wrong for this.
> 
> i observe from time to time during makeing some ports that a -DREENTRANT
> appears in most of all programmes comprise to that port. this is not a how
> to question but very close to that. 
> 
> can anyone here show me some code fragments of some coroutine written in
> a re-entrant style, for use with intel sure.
> 
> many thanks in advance.

Most any routine that doesn't maintain state with global variables,
or provides locking to serialize access to such globals is reentrant.

Reentrant functions also can not return pointers/references to static
objects, they must either return a pre-call allocated object or take
an address to an object to modify.

example (reentrant):

char *
reentrant(char *str)
{
  char *p;

  p = str;
  while ((p = strchr(p, ':')) != NULL) {
    *p = '-';
    p++;
  }
  return (str);
}

example (non-reentrant):

char *
nonreentrant(char *str)
{
  static char mystr[80];
  char *p;

  strncpy(mystr, str, sizeof(mystr));
  mystr[sizeof(mystr)-1] = '\0';

  p = mystr;
  while ((p = strchr(p, ':')) != NULL) {
    *p = '-';
    p++;
  }
  return (mystr);  /* returns static buffer */
}

-- 
-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]
"I have the heart of a child; I keep it in a jar on my desk."


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000618014128.A18462>