This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] [libgomp] make it possible to use OMP on both sides of a fork


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]