https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92546

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>:

https://gcc.gnu.org/g:b204d7722d30f44281dea3341070223475f1cff9

commit r11-5168-gb204d7722d30f44281dea3341070223475f1cff9
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Nov 19 13:36:15 2020 +0000

    libstdc++: Move std::thread to a new header

    This makes it possible to use std::thread without including the whole of
    <thread>. It also makes this_thread::get_id() and this_thread::yield()
    available even when there is no gthreads support (e.g. when GCC is built
    with --disable-threads or --enable-threads=single).

    In order for the std::thread::id return type of this_thread::get_id() to
    be defined, std:thread itself is defined unconditionally. However the
    constructor that creates new threads is not defined for single-threaded
    builds. The thread::join() and thread::detach() member functions are
    defined inline for single-threaded builds and just throw an exception
    (because we know the thread cannot be joinable if the constructor that
    creates joinable threads doesn't exit).

    The thread::hardware_concurrency() member function is also defined
    inline and returns 0 (as suggested by the standard when the value "is
    not computable or well-defined").

    The main benefit for most targets is that other headers such as <future>
    do not need to include the whole of <thread> just to be able to create a
    std::thread. That avoids including <stop_token> and std::jthread where
    not required. This is another partial fix for PR 92546.

    This also means we can use this_thread::get_id() and this_thread::yield()
    in <stop_token> instead of using the gthread functions directly. This
    removes some preprocessor conditionals, simplifying the code.

    libstdc++-v3/ChangeLog:

            PR libstdc++/92546
            * include/Makefile.am: Add new <bits/std_thread.h> header.
            * include/Makefile.in: Regenerate.
            * include/std/future: Include new header instead of <thread>.
            * include/std/stop_token: Include new header instead of
            <bits/gthr.h>.
            (stop_token::_S_yield()): Use this_thread::yield().
            (_Stop_state_t::_M_requester): Change type to std::thread::id.
            (_Stop_state_t::_M_request_stop()): Use this_thread::get_id().
            (_Stop_state_t::_M_remove_callback(_Stop_cb*)): Likewise.
            Use __is_single_threaded() to decide whether to synchronize.
            * include/std/thread (thread, operator==, this_thread::get_id)
            (this_thread::yield): Move to new header.
            (operator<=>, operator!=, operator<, operator<=, operator>)
            (operator>=, hash<thread::id>, operator<<): Define even when
            gthreads not available.
            * src/c++11/thread.cc: Include <memory>.
            * include/bits/std_thread.h: New file.
            (thread, operator==, this_thread::get_id, this_thread::yield):
            Define even when gthreads not available.
            [!_GLIBCXX_HAS_GTHREADS] (thread::join, thread::detach)
            (thread::hardware_concurrency): Define inline.

Reply via email to