Re: Reentrant functions and memory allocation
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Mar 2008 10:51:05 -0400
CBFalconer wrote:
fmassei@xxxxxxxxx wrote:I'm trying to put some old code in a portable, cross-platform
library and I'm facing a big problem: is there a standard,
platform-independent way to write a reentrant function that
allocate dynamic memory? In other words: is it safe to use
malloc() or free() in a thread-safe function?
No. Because the malloc system will be operating on it's own memory
areas, and is not re-entrant. You have to ensure that all accesses
to the malloc package are done through appropriate guards.
<off-topic>
For POSIX threads, malloc() et al. already contain whatever
guards are required, and you need provide no further protection
when calling them.
It's because of answers of this kind -- sort of right but
mostly not -- that it's been suggested you seek advice not here,
but on a forum where threading experts hang out.
</off-topic>
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Reentrant functions and memory allocation
- From: Richard
- Re: Reentrant functions and memory allocation
- References:
- Reentrant functions and memory allocation
- From: fmassei
- Re: Reentrant functions and memory allocation
- From: CBFalconer
- Reentrant functions and memory allocation
- Prev by Date: Re: Convert native character string to ASCII array of integers
- Next by Date: Re: Experiences using "register"
- Previous by thread: Re: Reentrant functions and memory allocation
- Next by thread: Re: Reentrant functions and memory allocation
- Index(es):
Relevant Pages
|