This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] [libgomp] make it possible to use OMP on both sides of a fork
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Nathaniel Smith <njs at pobox dot com>, gcc-patches at gcc dot gnu dot org
- Date: Fri, 14 Feb 2014 09:43:13 +0100
- Subject: Re: [PATCH] [libgomp] make it possible to use OMP on both sides of a fork
- Authentication-results: sourceware.org; auth=none
- References: <CAPJVwBkOF5GnrMr=4d1ehEKRGkY0tHzJzfXAYBguawu9y5wxXw at mail dot gmail dot com> <52FD37A1 dot 6040404 at redhat dot com> <20140214082124 dot GA20378 at tucnak dot redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Feb 14, 2014 at 09:21:24AM +0100, Jakub Jelinek wrote:
> Well, fork is async signal safe function, so calling malloc/free, or any
> kind of synchronization primitives is completely unsafe there.
>
> The only safe thing could be to atomically or in some global flag (or set
> some TLS flag?) and deal with the freeing next time you encounter omp
> parallel. But, the state of the old thread pool may be in some inconsistent
> shape.
BTW, I think far cleaner solution would be to discuss on Omp-lang and add
some standard omp_* function which would allow to throw away all the cached
OpenMP threads, after calling that function one could not assume
threadprivate vars (other than in the initial thread) preserve their values.
If this function would be only allowed outside of the parallel region (i.e.
if omp_in_parallel () == 0, or even just if omp_get_level () == 0) and
pretend to do
#pragma omp parallel num_threads (1)
;
i.e. something after which it isn't guaranteed to preserve threadprivate
vars, then the library could perform this at the point where it is safe to
do so (of course it wouldn't be async-signal-safe function) and isn't a
performance issue (calling it when you are expecting to soon launch another
#pragma omp parallel could of course slow things down a lot).
Anything else is going to be either unsafe, or leak memory.
Jakub