Re: Reentrant functions and memory allocation
- From: Richard <devr_@xxxxxxxxx>
- Date: Sun, 30 Mar 2008 16:56:49 +0200
Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx> writes:
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>
There are still people like Chuck there spouting nonsense. If you dont
know, dont answer.
.
- Follow-Ups:
- Re: Reentrant functions and memory allocation
- From: Willem
- Re: Reentrant functions and memory allocation
- References:
- Reentrant functions and memory allocation
- From: fmassei
- Re: Reentrant functions and memory allocation
- From: CBFalconer
- Re: Reentrant functions and memory allocation
- From: Eric Sosman
- Reentrant functions and memory allocation
- Prev by Date: Re: Experiences using "register"
- 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
|