This is the mail archive of the
mailing list for the GCC project.
Re: Re: Adding a new thread model to GCC
- From: "lh_mouse"<lh_mouse at 126 dot com>
- To: "Torvald Riegel"<triegel at redhat dot com>
- Cc: "gcc"<gcc at gcc dot gnu dot org>, "mingw-w64-public"<mingw-w64-public at lists dot sourceforge dot net>
- Date: Thu, 14 Apr 2016 10:24:53 +0800
- Subject: Re: Re: Adding a new thread model to GCC
- Authentication-results: sourceware.org; auth=none
- References: <2f3897eb dot bbc0e dot 1540ee9aa0b dot Coremail dot lh_mouse at 126 dot com><1460569249 dot 3869 dot 382 dot camel at localhost dot localdomain>
Yes I learnt those *ByAddress* functions a few months ago and was shocked that Microsoft had plagiarized futex from Linux.
As you have pointed out already, those APIs are only available on Windows 8 and later.
If we need fuex semantics on Windows 7 and earlier, we must simulate it.
However, since futexes and keyed events work differently, simulation of futexes using keyed events would:
0) require a lot of work, and
1) suffer from performance penalty just like if we simulate keyed events on Windows 2000.
The major difference is that, the FUTEX_WAIT syscall is an atomic compare-and-sleep operation, while the NtWaitForKeyedEvent syscall provides no comparison.
Instead, the NtReleasedKeyedEvent syscall blocks the current thread until one thread is woken up, while FUTEX_WAKE does nothing and returns immediately.
So here is my condition: in no event shall portability harm either efficiency or maintainability.
Linux and Windows work differently. I consider it 'harmful' to make one look like the other.
åääïTorvald Riegel <email@example.com>
äéïRe: Adding a new thread model to GCC
On Wed, 2016-04-13 at 17:17 +0800, lh_mouse wrote:
> Hi all,
> The 'win32' thread model of gcc has been there since long long ago, being compatible with very old Windows versions, also having a number of drawbacks:
> 0) its implementation is very inefficient, and
> 1) its mutexes and condition variables require dynamic initialization and are unusable in C++11 as std::mutex requires a `constexpr` constructor, and
> 2) allocating a number of rarely used mutexes or condition variables would eventually make the system run out of kernel objects.
> As a solution for 1) and 2), Microsoft introduced keyed events, details of which can be found here:
Have you looked at WaitOnAddress and WakeByAddressSingle /
WakeByAddressAll too? AFAIK this is new in Windows 8, and seems similar
I think it might be better to get a std::synchronic (or similar)
implementation into GCC, and then use these to implement at least the
One benefit would be that we then have one place where we have optimized
spinning/blocking in libstdc++ on Windows, and less platform-specific