public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/33578] __gnu_parallel::yield means what?
Date: Tue, 16 May 2023 20:24:58 +0000	[thread overview]
Message-ID: <bug-33578-4-xAX3vVcJjB@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-33578-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For std::this_thread::yield() we do:

    inline void
    yield() noexcept
    {
#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
      __gthread_yield();
#endif
    }

And gthr-win32.h has:

__GTHREAD_WIN32_INLINE int
__gthread_yield (void)
{
  Sleep (0);
  return 0;
}

For atomics we also support using the x86 pause instruction

    inline void
    __thread_yield() noexcept
    {
#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
     __gthread_yield();
#endif
    }

    inline void
    __thread_relax() noexcept
    {
#if defined __i386__ || defined __x86_64__
      __builtin_ia32_pause();
#else
      __thread_yield();
#endif
    }



For Parallel Mode maybe we should just use __gthread_yield() everywhere?
gthr-win32.h already takes care of hiding the Win32 API. Since Parallel Mode is
likely to get removed at some point (now that we have the parallel STL algos
from C++17) I don't see any point in revisiting its implementation w.r.t using
of yield at all (comment 1).

tl;dr let's not reinvent the wheel when we already have portable code for
yielding, and don't want to redesign the parallel mode.

  parent reply	other threads:[~2023-05-16 20:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-33578-4@http.gcc.gnu.org/bugzilla/>
2023-05-16 19:41 ` pinskia at gcc dot gnu.org
2023-05-16 20:24 ` redi at gcc dot gnu.org [this message]
2007-09-28  0:41 [Bug libstdc++/33578] New: libstdc++ parallel mode broken on mingw32 dannysmith at users dot sourceforge dot net
2007-10-16 17:24 ` [Bug libstdc++/33578] __gnu_parallel::yield means what? bkoz at gcc dot gnu dot org

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=bug-33578-4-xAX3vVcJjB@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).