public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Eric Botcazou <botcazou@adacore.com>
Cc: i.nixman@autistici.org, libstdc++@gcc.gnu.org,
	gcc-patches@gcc.gnu.org,  Jonathan Yong <10walls@gmail.com>
Subject: Re: Adding a new thread model to GCC
Date: Fri, 16 Dec 2022 17:18:04 +0000	[thread overview]
Message-ID: <CACb0b4nhp89FmAHkuYEZs=nsL4Ge3oEV3G_gZ28FkDuud+Zxpg@mail.gmail.com> (raw)
In-Reply-To: <21655510.EfDdHjke4D@fomalhaut>

[-- Attachment #1: Type: text/plain, Size: 8136 bytes --]

On Mon, 31 Oct 2022 at 09:19, Eric Botcazou via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
> I have attached a revised version of the original patch at:
>   https://gcc.gnu.org/legacy-ml/gcc-patches/2019-06/msg01840.html
>
> This reimplements the GNU threads library on native Windows (except for the
> Objective-C specific subset) using direct Win32 API calls, in lieu of the
> implementation based on semaphores.  This base implementations requires
> Windows XP/Server 2003, which was the default minimal setting of MinGW-W64
> until end of 2020.  This also adds the support required for the C++11 threads,
> using again direct Win32 API calls; this additional layer requires Windows
> Vista/Server 2008 and is enabled only if _WIN32_WINNT >= 0x0600.
>
> This also changes libstdc++ to pass -D_WIN32_WINNT=0x0600 but only when the
> switch --enable-libstdcxx-threads is passed, which means that C++11 threads
> are still disabled by default *unless* MinGW-W64 itself is configured for
> Windows Vista/Server 2008 or later by default (this has been the case in
> the development version since end of 2020, for earlier versions you can
> configure it --with-default-win32-winnt=0x0600 to get the same effect).
>
> I only manually tested it on i686-w64-mingw32 and x86_64-w64-mingw32 but
> AdaCore has used it in their C/C++/Ada compilers for 3 years now and the
> 30_threads chapter of the libstdc++ testsuite was clean at the time.

The libgcc parts look reasonable to me, but I can't approve them.
Maybe Jonathan Yong can approve those parts as mingw-w64 target
maintainer, or maybe a libgcc approver can do so.

The libstdc++ parts are OK for trunk. IIUC they could go in
separately, they just wouldn't be very much use without the libgcc
changes.


> 2022-10-31  Eric Botcazou  <ebotcazou@adacore.com>
>
> libgcc/
>         * config.host (i[34567]86-*-mingw*): Add thread fragment after EH one
>         as well as new i386/t-slibgcc-mingw fragment.
>         (x86_64-*-mingw*): Likewise.
>         * config/i386/gthr-win32.h: If _WIN32_WINNT is at least 0x0600, define
>         both __GTHREAD_HAS_COND and __GTHREADS_CXX0X to 1.
>         Error out if _GTHREAD_USE_MUTEX_TIMEDLOCK is 1.
>         Include stdlib.h instead of errno.h and do not include _mingw.h.
>         (CONST_CAST2): Add specific definition for C++.
>         (ATTRIBUTE_UNUSED): New macro.
>         (__UNUSED_PARAM): Delete.
>         Define WIN32_LEAN_AND_MEAN before including windows.h.
>         (__gthread_objc_data_tls): Use TLS_OUT_OF_INDEXES instead of (DWORD)-1.
>         (__gthread_objc_init_thread_system): Likewise.
>         (__gthread_objc_thread_get_data): Minor tweak.
>         (__gthread_objc_condition_allocate): Use ATTRIBUTE_UNUSED.
>         (__gthread_objc_condition_deallocate): Likewise.
>         (__gthread_objc_condition_wait): Likewise.
>         (__gthread_objc_condition_broadcast): Likewise.
>         (__gthread_objc_condition_signal): Likewise.
>         Include sys/time.h.
>         (__gthr_win32_DWORD): New typedef.
>         (__gthr_win32_HANDLE): Likewise.
>         (__gthr_win32_CRITICAL_SECTION): Likewise.
>         (__gthr_win32_CONDITION_VARIABLE): Likewise.
>         (__gthread_t): Adjust.
>         (__gthread_key_t): Likewise.
>         (__gthread_mutex_t): Likewise.
>         (__gthread_recursive_mutex_t): Likewise.
>         (__gthread_cond_t): New typedef.
>         (__gthread_time_t): Likewise.
>         (__GTHREAD_MUTEX_INIT_DEFAULT): Delete.
>         (__GTHREAD_RECURSIVE_MUTEX_INIT_DEFAULT): Likewise.
>         (__GTHREAD_COND_INIT_FUNCTION): Define.
>         (__GTHREAD_TIME_INIT): Likewise.
>         (__gthr_i486_lock_cmp_xchg): Delete.
>         (__gthr_win32_create): Declare.
>         (__gthr_win32_join): Likewise.
>         (__gthr_win32_self): Likewise.
>         (__gthr_win32_detach): Likewise.
>         (__gthr_win32_equal): Likewise.
>         (__gthr_win32_yield): Likewise.
>         (__gthr_win32_mutex_destroy): Likewise.
>         (__gthr_win32_cond_init_function): Likewise if __GTHREADS_HAS_COND is 1.
>         (__gthr_win32_cond_broadcast): Likewise.
>         (__gthr_win32_cond_signal): Likewise.
>         (__gthr_win32_cond_wait): Likewise.
>         (__gthr_win32_cond_timedwait): Likewise.
>         (__gthr_win32_recursive_mutex_init_function): Delete.
>         (__gthr_win32_recursive_mutex_lock): Likewise.
>         (__gthr_win32_recursive_mutex_unlock): Likewise.
>         (__gthr_win32_recursive_mutex_destroy): Likewise.
>         (__gthread_create): New inline function.
>         (__gthread_join): Likewise.
>         (__gthread_self): Likewise.
>         (__gthread_detach): Likewise.
>         (__gthread_equal): Likewise.
>         (__gthread_yield): Likewise.
>         (__gthread_cond_init_function): Likewise if __GTHREADS_HAS_COND is 1.
>         (__gthread_cond_broadcast): Likewise.
>         (__gthread_cond_signal): Likewise.
>         (__gthread_cond_wait): Likewise.
>         (__gthread_cond_timedwait): Likewise.
>         (__GTHREAD_WIN32_INLINE): New macro.
>         (__GTHREAD_WIN32_COND_INLINE): Likewise.
>         (__GTHREAD_WIN32_ACTIVE_P): Likewise.
>         Define WIN32_LEAN_AND_MEAN before including windows.h.
>         (__gthread_once): Minor tweaks.
>         (__gthread_key_create): Use ATTRIBUTE_UNUSED and TLS_OUT_OF_INDEXES.
>         (__gthread_key_delete): Minor tweak.
>         (__gthread_getspecific): Likewise.
>         (__gthread_setspecific): Likewise.
>         (__gthread_mutex_init_function): Reimplement.
>         (__gthread_mutex_destroy): Likewise.
>         (__gthread_mutex_lock): Likewise.
>         (__gthread_mutex_trylock): Likewise.
>         (__gthread_mutex_unlock): Likewise.
>         (__gthr_win32_abs_to_rel_time): Declare.
>         (__gthread_recursive_mutex_init_function): Reimplement.
>         (__gthread_recursive_mutex_destroy): Likewise.
>         (__gthread_recursive_mutex_lock): Likewise.
>         (__gthread_recursive_mutex_trylock): Likewise.
>         (__gthread_recursive_mutex_unlock): Likewise.
>         (__gthread_cond_destroy): New inline function.
>         (__gthread_cond_wait_recursive): Likewise.
>         * config/i386/gthr-win32.c: Delete everything.
>         Include gthr-win32.h to get the out-of-line version of inline routines.
>         Add compile-time checks for the local version of the Win32 types.
>         * config/i386/gthr-win32-cond.c: New file.
>         * config/i386/gthr-win32-thread.c: Likewise.
>         * config/i386/t-gthr-win32: Add config/i386/gthr-win32-thread.c to the
>         EH part, config/i386/gthr-win32-cond.c and config/i386/gthr-win32.c to
>         the static version of libgcc.
>         * config/i386/t-slibgcc-mingw: New file.
>         * config/i386/libgcc-mingw.ver: Likewise.
> libstdc++-v3/
>         * acinclude.m4 (GLIBCXX_EXPORT_FLAGS): Substitute CPPFLAGS.
>         (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Set ac_has_sched_yield and
>         ac_has_win32_sleep to yes for MinGW.  Change HAVE_WIN32_SLEEP
>         into _GLIBCXX_USE_WIN32_SLEEP.
>         (GLIBCXX_CHECK_GTHREADS): Add _WIN32_THREADS to compilation flags for
>         Win32 threads and force _GTHREAD_USE_MUTEX_TIMEDLOCK to 0 for them.
>         Add -D_WIN32_WINNT=0x0600 to compilation flags if yes was configured
>         and add it to CPPFLAGS on success.
>         * config.h.in: Regenerate.
>         * configure: Likewise.
>         * config/os/mingw32-w64/os_defines.h (_GLIBCXX_USE_GET_NPROCS_WIN32):
>         Define to 1.
>         * config/os/mingw32/os_defines.h (_GLIBCXX_USE_GET_NPROCS_WIN32): Ditto
>         * src/c++11/thread.cc (get_nprocs): Provide Win32 implementation if
>         _GLIBCXX_USE_GET_NPROCS_WIN32 is defined.  Replace HAVE_WIN32_SLEEP
>         with USE_WIN32_SLEEP.
>         * testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc: Add
>         missing conditional compilation.
>         * testsuite/lib/libstdc++.exp (check_v3_target_sleep): Add support for
>         _GLIBCXX_USE_WIN32_SLEEP.
>         (check_v3_target_nprocs): Likewise for _GLIBCXX_USE_GET_NPROCS_WIN32.
>
> --
> Eric Botcazou

[-- Attachment #2: p13.diff --]
[-- Type: application/x-patch, Size: 56497 bytes --]

  parent reply	other threads:[~2022-12-16 17:18 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-01 18:34 LIU Hao
2022-10-01 20:02 ` Bernhard Reutner-Fischer
2022-10-21  9:58 ` Jonathan Wakely
2022-10-21 10:09   ` i.nixman
2022-10-21 10:48     ` Jonathan Wakely
2022-10-21 10:55       ` i.nixman
2022-10-21 11:36     ` LIU Hao
2022-10-21 11:54       ` i.nixman
2022-10-21 12:19         ` LIU Hao
2022-10-21 12:34           ` i.nixman
2022-10-24  3:40             ` LIU Hao
2022-10-24 20:50               ` Jacek Caban
2022-10-21 11:44   ` Eric Botcazou
2022-10-21 11:55     ` i.nixman
2022-10-24  6:53     ` i.nixman
2022-10-24  8:15       ` Eric Botcazou
2022-10-24  8:20         ` i.nixman
2022-10-31  9:18       ` Eric Botcazou
2022-10-31 15:22         ` i.nixman
2022-11-01  5:22         ` i.nixman
2022-11-01  9:09           ` Eric Botcazou
2022-11-02 12:05             ` i.nixman
2022-11-02 21:27               ` Eric Botcazou
2022-11-02 21:40                 ` i.nixman
2022-12-16 17:18         ` Jonathan Wakely [this message]
2022-12-16 19:20           ` Eric Botcazou
2022-12-22 12:21             ` Jonathan Yong
2022-12-22 12:28               ` i.nixman
2022-12-23 23:59                 ` Jonathan Yong
2022-12-24  5:58                   ` NightStrike
2022-12-24  6:27                     ` i.nixman
2022-12-24 13:50                     ` i.nixman
2022-12-24 15:42                       ` i.nixman
2022-12-24 15:57                         ` i.nixman
2022-12-24 21:22                           ` i.nixman
2022-12-25  1:10                             ` Jonathan Yong
2023-01-09 21:56                             ` Eric Botcazou
2022-12-24  6:22                   ` i.nixman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACb0b4nhp89FmAHkuYEZs=nsL4Ge3oEV3G_gZ28FkDuud+Zxpg@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=10walls@gmail.com \
    --cc=botcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=i.nixman@autistici.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).