Path: utzoo!attcan!uunet!cs.utexas.edu!rice!sun-spots-request From: henry@zoo.toronto.edu Newsgroups: comp.sys.sun Subject: Re: Is malloc reentrant Keywords: SunOS Message-ID: <9548@brazos.Rice.edu> Date: 1 Jul 90 04:32:14 GMT Sender: root@rice.edu Organization: Sun-Spots Lines: 21 Approved: Sun-Spots@rice.edu X-Refs: Original: v9n245 X-Sun-Spots-Digest: Volume 9, Issue 245, message 8 >Is malloc guaranteed to be reentrant, if not is it reentrant on any >systems? Nothing in the C library is guaranteed reentrant by any manufacturer-independent specification, e.g. ANSI C. I would be very surprised to see it reentrant on any implementation that hadn't been written with something like user-level threads in mind (and suitable tools on hand to aid in writing it). Malloc inherently relies on global data structures to remember the state of memory, and nothing that relies on global variables is reentrant in general. In the absence of threads or other such primitives for parallelism, the only way you'd get malloc re-entered would be from a signal handler. BEWARE: there is almost nothing you can do safely and portably in a signal handler. ANSI C guarantees that you can (a) call signal() for the same signal, (b) assign a value to a static variable of one very specific type, and (c) *nothing else*. 1003.1 makes some somewhat stronger promises, but the ability to call malloc() is not among them. Henry Spencer at U of Toronto Zoology henry@zoo.toronto.edu utzoo!henry