This is a discussion on Re: Is malloc() function provided in <stdlib.h> thread-safe? - Unix ; firstname.lastname@example.org writes: > Does anyone have experience on the thread-safty issue with malloc()? > Some people said this function provided in stdlib.h is not thread- > safe, but someone said it is thread safe. Is it possible this > function ...
> Does anyone have experience on the thread-safty issue with malloc()?
> Some people said this function provided in stdlib.h is not thread-
> safe, but someone said it is thread safe. Is it possible this
> function evolves from thread-unsafe to thread-safe in recent years?
> How could i find out?
The C standard does not yet specify the behaviour of threads, so
it does not say whether malloc() or any other function can safely
be called from multiple threads at the same time. However, I
would expect malloc() to be thread-safe in any implementation
that supports threads, because otherwise the callers would have
to provide their own locking and it would be unnecessarily
difficult to make independent libraries cooperate in this.
> I am using the C library coming with GNU linux distribution.
The GNU C Library claims to follow several standards, including
the Single Unix Specification, whose version 2 specifies:
# All interfaces defined by this specification will be
# thread-safe, except that the following interfaces need not be
and the list that follows does not include malloc(), which SUSv2
does define. So the GNU C Library must also have a thread-safe
malloc() in order to conform.
Unix standards may be more on topic at comp.unix.programmer though.
comp.lang.c.moderated - moderation address: email@example.com -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.