"is malloc thread-safe?" Code Answer

1

i read somewhere that if you compile with -pthread, malloc becomes thread safe. i´m pretty sure its implementation dependant though, since malloc is ansi c and threads are not.

if we are talking gcc:

compile and link with -pthread and malloc() will be thread-safe, on x86 and amd64.

http://groups.google.com/group/comp.lang.c.moderated/browse_thread/thread/2431a99b9bdcef11/ea800579e40f7fa4

another opinion, more insightful

{malloc, calloc, realloc, free, posix_memalign} of glibc-2.2+ are thread safe

http://linux.derkeiler.com/newsgroups/comp.os.linux.development.apps/2005-07/0323.html

By Jeff Handley on January 26 2022

Answers related to “is malloc thread-safe?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.