[committed] libstdc++: Use __libc_single_threaded to optimise atomics [PR 96817]
Florian Weimer
fw@deneb.enyo.de
Sun Sep 27 19:15:33 GMT 2020
* Jonathan Wakely via Libstdc:
> We can't use __libc_single_threaded to replace __gthread_active_p
> everywhere. If we replaced the uses of __gthread_active_p in std::mutex
> then we would elide the pthread_mutex_lock in the code below, but not
> the pthread_mutex_unlock:
>
> std::mutex m;
> m.lock(); // pthread_mutex_lock
> std::thread t([]{}); // __libc_single_threaded = false
> t.join();
> m.unlock(); // pthread_mutex_unlock
Thanks for implementing this.
Eliding the mutex lock is a bit iffy because the mutex may reside in a
shared mapping. For doing the same optimization in glibc, we will
have to check if the mutex is process-private or not.
More information about the Libstdc++
mailing list