|
Message-ID: <20201123165833.GU1312820@redhat.com> Date: Mon, 23 Nov 2020 16:58:33 +0000 From: Jonathan Wakely <jwakely@...hat.com> To: Rich Felker <dalias@...c.org> Cc: Арсений <a@...r0n.science>, musl@...ts.openwall.com, Florian Weimer <fw@...eb.enyo.de> Subject: Re: Mutexes are not unlocking On 23/11/20 09:56 -0500, Rich Felker wrote: >On Mon, Nov 23, 2020 at 12:24:28PM +0000, Jonathan Wakely wrote: >> On 22/11/20 23:05 +0300, Арсений wrote: >> > >> >Hello, >> > >> >I fixed the problem by making a workaround. Specifying -D_GLIBCXX_GTHREAD_USE_WEAK=0 forces libstdc++ headers do not use weak symbols. Mutexes are correctly locked and unlocked now. >> >> That might "work" but is unsupported, because that macro is for >> libstdc++'s internal use, not for users to define/undefine. >> >> But then libstdc++ doesn't support being compiled/linked against a >> glibc libstdc++ and then running against musl at runtime (I didn't >> even know that was an option until today) so one more unsupported >> thing probably won't hurt :-) >> >> Maybe we should just bless the use of that macro as supported, which >> would solve https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89714 > >As you noted in comment 2, that won't fix the uses internal to >libstdc++.{so,a}, only the inlined ones. I think this could give the >wrong behavior in the opposite direction -- calling unlock without >lock, thereby causing an error (for error-checking mutexes) or trap >(if UB catching traps are in place for other types). I've just had a quick look, and (for linux targets) the only case I found where there's a lock outside the library (in user code) and a corresponding unlock inside the library, or vice versa, is in std::notify_all_at_thread_exit. (I only looked very quickly, so there might be other cases I missed). It does look like it would be possible for user code to lock the mutex (via a direct all to the non-weak pthread_mutex_lock) and then call std::notify_all_at_thread_exit() which unlock the mutex, which would test __gthread_active_p, which would incorrectly think the program is single-threaded, and not call pthread_mutex_unlock. So recommending -D_GLIBCXX_GTHREAD_USE_WEAK=0 is a bad idea. We would need a better way for users to override the checks.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.