From: Jakub Jelinek <jakub@redhat.com>
To: Nathaniel Smith <njs@pobox.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: ping x 7: [PATCH] [libgomp] make it possible to use OMP on both sides of a fork
Date: Thu, 16 Oct 2014 16:17:00 -0000 [thread overview]
Message-ID: <20141016155225.GK10376@tucnak.redhat.com> (raw)
In-Reply-To: <CAPJVwB=_DsJLeMJbdJ4Y3ajXdQJkOxHkLSAoSCMCVk=wqpejsg@mail.gmail.com>
On Mon, Oct 13, 2014 at 10:16:19PM +0100, Nathaniel Smith wrote:
> Got total silence the last 4 times I posted this, and users have been
> bugging me about it offline, so trying again.
>
> This patch fixes a showstopper problem preventing the transparent use
> of OpenMP in scientific libraries, esp. with Python. Specifically, it
> is currently not possible to use GNU OpenMP -- even in a limited,
> temporary manner -- in any program that uses (or might use) fork() for
> parallelism, even if the fork() and the use of OpenMP occur at totally
> different times. This limitation is unique to GNU OpenMP -- every
> competing OpenMP implementation already contains something like this
> patch. While technically not fully POSIX-compliant (because POSIX
> gives much much weaker guarantees around fork() than any real Unix),
> the approach used in this patch (a) performs only POSIX-compliant
> operations when the host program is itself fully POSIX-compliant, and
> (b) actually works perfectly reliably in practice on all commonly used
> platforms I'm aware of.
1) gomp_we_are_forked in your patch will attempt to free the pool
of the thread that encounters it, which is racy; consider a program
after fork calling pthread_create several times, each thread
thusly created then ~ at the same time doing #pragma omp parallel
and the initial thread too. You really should clean up the pool
data structure only in the initial thread and nowhere else;
for native TLS (non-emulated, IE model) the best would be to have a flag
in the gomp_thread_pool structure,
struct gomp_thread *thr = gomp_thread ();
if (thr && thr->thread_pool)
thr->thread_pool->after_fork = true;
should in that case be safe in the atfork child handler.
For !HAVE_TLS or emulated TLS not sure if it is completely safe,
it would call pthread_getspecific. Perhaps just don't register
atfork handler on those targets at all?
2) can you explain why are you removing the cleanups from
gomp_free_pool_helper ?
3) you can call pthread_atfork many times (once for each pthread
that creates a thread pool), that is undesirable, you want to do that
only if the initial thread creates thread pool
4) the testcase is clearly not portable enough, should be probably limited
to *-*-linux* only, fork etc. will likely not work on many targets.
In any case, even with the patch, are you aware that you'll leak megabytes
of thread stacks etc.?
Jakub
next prev parent reply other threads:[~2014-10-16 15:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-13 22:35 Nathaniel Smith
2014-10-16 16:17 ` Jakub Jelinek [this message]
2014-10-20 6:57 ` Nathaniel Smith
[not found] ` <CAPJVwBm4KSc07ReQmTyL6FvBCK06B_AbVFoQh02BrpjucpXgRw@mail.gmail.com>
2014-11-06 17:01 ` Nathaniel Smith
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=20141016155225.GK10376@tucnak.redhat.com \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=njs@pobox.com \
/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).