Cc: address@hidden, address@hidden, address@hidden
From: Paul Eggert <address@hidden>
Date: Tue, 1 Nov 2016 09:28:34 -0700
On 11/01/2016 08:11 AM, Eli Zaretskii wrote:
> Only C11 mandates that malloc/realloc/free shall be thread-safe, and
we don't yet require C11.
This is too pessimistic. C11 was the first C standard to talk about
threads, which is why it's the first C standard to specify whether
malloc is thread-safe. In practice it should be safe to assume that
malloc is thread-safe on multithreaded platforms, as C programmers would
have revolted en masse otherwise.
"It should be safe" and "it's safe" are 2 different things.
> gmalloc is only thread-safe if Emacs is built with pthreads.
Yes, and that's what one would expect. If you build Emacs in
single-threaded mode, malloc won't be thread-safe. But in the normal
case nowadays, malloc should be thread-safe.
pthreads is not the only way to have threads.
> ralloc is not thread-safe at all.
Yes, and ralloc as it stands should not be used on modern platforms. We
clearly need to move in that direction anyway.
We do move in that direction, but we aren't there yet.
> xmalloc calls memory_full, which manipulates global state and calls
xsignal, so that is not thread-safe, either.
That's fine, so long as xmalloc is called only in the Emacs Lisp thread.
I'd imagine any code that wants to allocate from the heap will call
xmalloc, as we never call malloc directly in Emacs AFAIK.