comp.lang.c
[Top] [All Lists]

Re: Reentrant functions and memory allocation

Subject: Re: Reentrant functions and memory allocation
From:
Date: Sun, 30 Mar 2008 07:14:32 -0700 PDT
Newsgroups: comp.lang.c

On 30 Mar, 15:08, Flash Gordon <s...@xxxxxxxxxxxxxxxxxx> wrote:
> fmas...@xxxxxxxxx wrote, On 30/03/08 13:45:
>
> > Dear all,
> > 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?
>
> Re-entrancy and thread safety are not the same. The C standard does not
> know about threads but does know a little about reentrancy, and
> malloc/realloc/free are not required to be reentrant. You might find
> comp.programming.threads a better place to ask about how you can solve
> your threading problems.
> --
> Flash Gordon

This is what I was worried about. I just want to write something that
can be safely used in a multi-threaded project, if someone wants to.
Should I consider to work only with pre-allocated memory? Doing this
way the problem can be moved outside the library. Is this the only
solution I have?

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy