|
From: | Daniel Colascione |
Subject: | Re: Can we go GTK-only? |
Date: | Tue, 1 Nov 2016 10:16:07 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
On 11/01/2016 10:08 AM, Eli Zaretskii wrote:
Cc: address@hidden, address@hidden, address@hidden From: Daniel Colascione <address@hidden> Date: Tue, 1 Nov 2016 09:54:51 -0700> 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.On any modern system POSIX system it is. Counterexample, please.You can find them yourself if you are interested. I have more important things to do with my time.
What other thread mechanism? Windows threads? Malloc is thread-safe. GNU Pth? Not really multi-threaded, so malloc is safe. Old-fashioned pre-pthreads Sun threads? We don't support that platform, and I strongly suspect malloc was safe there too.
You're the one making the unusual claim, so you're the one who needs to provide evidence.
> 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.That's because we want xmalloc to handle memory exhaustion in a sane way. A thread calling system malloc on its own can handle memory exhaustion a different way. Memory exhaustion being reported in some way is what really matters.We'd have to write that stuff before this issue can be regarded as solved.
It'll be solved in whatever code does the memory allocation. Nobody knows yet what that looks like, because it isn't been written, but it's obvious in broad strokes that you can check whether malloc returns NULL and stop what you're doing or set an error flag _somehow_. There's no technical problem to be solved: just code to be written.
Like I said: we are barely out of the woods, so allocations from the heap in non-main threads should be avoided.This restriction makes a big class of programs very difficult to write.That's what I'm saying: that class of programs is not yet feasible for Emacs. In a couple of years, maybe.
What will have changed in a few years? If you have evidence that we have a problem now, please provide it. If your presupposition of evidence-free now, it'll be evidence-free in a few years too.
Besides, in my Emacs right now, I have in addition to the main thread a generic glib worker thread, a dconf worker thread, and a gdbus thread.We are not talking about your Emacs or mine. (In my Emacs, those problems cannot happen at all, because as you know on Windows each DLL calls the memory allocator it was linked against, so the tricks Emacs plays with its private malloc are harmless, because no external library will ever call it.) But I was talking about the mainstream Emacs on J.R.Hacker's random machine out there. That is the platform about whose stability I worry.
"R.Hacker's random machine" is not a supported platform. Name a supported platform that concerns you.
[Prev in Thread] | Current Thread | [Next in Thread] |