From owner-freebsd-questions Sun Jun 18 1:41:42 2000 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id AC28237B770 for ; Sun, 18 Jun 2000 01:41:34 -0700 (PDT) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id e5I8fSU29631; Sun, 18 Jun 2000 01:41:28 -0700 (PDT) Date: Sun, 18 Jun 2000 01:41:28 -0700 From: Alfred Perlstein To: pirat Cc: questions@FreeBSD.ORG Subject: Re: reentrant code for Intel Message-ID: <20000618014128.A18462@fw.wintelcom.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i In-Reply-To: ; from pirat@access.inet.co.th on Sun, Jun 18, 2000 at 03:20:03PM +0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * pirat [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