Web lists-archives.com

Re: problem with mmap and fork()




On 23. 02. 19 1:02, Glyn Gowing wrote:
> Hello everyone,
> 
> I have a program (attached) that works correctly on my mac but does
> not work with Cygwin on Windows 10. I'm running the latest version of
> Cygwin (downloaded the updates two days ago) and using gcc as the c
> compiler.
> 
> What happens in the buggy execution is that the child obtains a lock
> before the parent releases it. I'm using mmap and a pthread_mutex_t
> object along with fork(). Again, this exact code works correctly on my
> Mac running Mojave.
> 
> I've looked at the archives and online and I can't find any hints as
> to what I may be doing incorrectly here
> 

You cannot fork() and keep using threading primitives in the child. The
child has only one thread and the mutexes are usually in a state that
can be inconsistent. Basically, the only safe thing to do in
multithreaded process after fork is to exec() and reinitialize your
application.

-- 
VH

Attachment: signature.asc
Description: OpenPGP digital signature