In said:
Hi all,
Does anyone have experience on the thread-safty issue with malloc()?
Possibly. In any case, "thread-safety" is irrelevant here. The C standard
does not include "threads", and does not address whether a specific library
function is "thread-safe" or not.
However, your C compiler /implementation/ may recognize "threads" in your
environment. To determine if your /implementation/ supplies "thread-safe"
standard library functions, you should check your /implementation's/
documentation or ask about the subject in the appropriate /implementation/
forum.
Some people said this function provided in stdlib.h
stdlib.h does not provide any function. It provides function declarations
(prototypes for the function's calling parameters and return value),
macros, and other sort of information. The /function/ will be provided in
one of your implementation's libraries.
is not thread-safe, but someone said it is thread safe.
"Some people" "Someone"? How about asking the implementers, or checking the
implementation documentation? Remember, even here, we are "some people",
and I am "someone".
Is it possible this
function evolves from thread-unsafe to thread-safe in recent years?
It is, in any specific implementation. An implementation can even offer both
thread-safe and thread-unsafe versions of the same function, so long as the
mechanism that selects the function is outside of the C language (like a
compiler or linker option, or the specification of an alternate library
during linkage).
Read your compiler's documentation. Read the documentation on your runtime.
I am using the C library coming with GNU linux distribution.
<OT>
Assuming a recent version of GCC and a recent implementation of Linux, you
have may have
1) no threading support at all,
2) "Linux threads" support, or
3) "NPTL" threads support
"Linux Threads" and "NPTL threads" runtimes are implemented in different
(non-C-standard) libraries, which provide both the threading primative
functions and (possibly) "thread-safe" replacement functions for some
thread-unsafe functions in the standard and POSIX libraries.
If your environment does not include either "Linux Threads" or "NPTL"
threads, then you likely have a C runtime library that does not recognize
threads, and thus has a questionable "thread-safety" (functions /may/ be
thread-safe, but there is no guarantee). Check your /usr/doc/gcc*
documentation, and the manpage for each function you intend to use, and
look for the instructions on how to use the appropriate threading library.
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------