[PATCH] Add support for C++2a stop_token

Jonathan Wakely jwakely@redhat.com
Mon Nov 18 12:28:00 GMT 2019


On 15/11/19 23:43 +0000, Jonathan Wakely wrote:
>On 15/11/19 14:40 +0000, Jonathan Wakely wrote:
>>On 15/11/19 14:38 +0000, Jonathan Wakely wrote:
>>>On 13/11/19 17:59 -0800, Thomas Rodgers wrote:
>>>>+  // TODO verify the standard requires this
>>>>+#if 0
>>>>+  // register another callback
>>>>+  bool cb3called{false};
>>>>+  std::stop_callback scb3{stok, [&]
>>>>+                                {
>>>>+                                  cb3called = true;
>>>>+                                }};
>>>>+  VERIFY(ssrc.stop_possible());
>>>>+  VERIFY(ssrc.stop_requested());
>>>>+  VERIFY(stok.stop_possible());
>>>>+  VERIFY(stok.stop_requested());
>>>>+  VERIFY(!cb1called);
>>>>+  VERIFY(cb2called);
>>>>+  VERIFY(cb3called);
>>>>+#endif
>>>
>>>The working draft definitely requires this:
>>>
>>>Effects: Initializes callback with std::forward<C>(cb). If st.stop_requested() is true, then
>>>std::forward<Callback>(callback)() is evaluated in the current thread before the constructor
>>>returns.
>>
>>I've committed this fix to the nostopstate initializer, so it defines
>>a variable, instead of declaring a function. I've also added a test
>>that uses the stop_source(nostopstate_t) constructor, and a few other
>>tweaks to include the new header where it's needed.
>
>This fixes some other issues I noticed, and should fix the failues for
>the single-threaded multilib on AIX.

And a couple more bugs fixed by this patch.

The std::jthread::get_id() function was missing a return statement.

The is_invocable check needs to be done using decayed types, as they'll
be forwarded to std::invoke as rvalues.

Also reduce header dependencies for the <thread> header. We don't need 
to include <functional> for std::jthread because <bits/invoke.h> is
already included, which defines std::__invoke. We can also remove
<bits/functexcept.h> which isn't used at all. Finally, when
_GLIBCXX_HAS_GTHREADS is not defined there's no point including any
other headers, since we're not going to define anything in <thread>
anyway.

Tested powerpc64le-linux, committed to trunk.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 12191 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20191118/71797718/attachment.bin>


More information about the Libstdc++ mailing list