www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/02/23/01:35:48

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-type; q=dns; s=default; b=i1CB2Wy
cQMd1Ppr22Z+P4yexPcDsrE0UAorW1h3HDYQe2xpcw2Qb/be5QgIpYGXU09VI//6
bHy+kqCPXrTVE3a10ZN7M69z42hSj4JOA/vHILkK/Dn+jBUQuzUZtSItDBHVy+oN
Hkql6o1FuH4kouhrkpWKOt0r8bsgID4lA0DE=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-type; s=default; bh=+/HF4tZSg8yN2
/DWL9A4F+4mvEE=; b=qqQUDnnH++hkh2MOkJy9G6wSsuq5nWuYcEFfEv9hvT5Jk
J2lI1S2RQCTpBZ0pxVupjGkVBecT0AECj5MBBf1l+rNzrjXkVtukAO7W3wrTK7e9
ZbXcHAN2lwsq4mf8298dbcB3DPNPSxfw2IsLDVNmau1mHbHSOHWCXnYEH5xkgU=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,HK_RANDOM_ENVFROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=Canada, canada, Glyn, Hx-languages-length:1647
X-HELO: mail-qt1-f169.google.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=WO+BTNboBpMqH1UyvXc/LlLA8JrHUYesLj43oa5p/y0=; b=VGXC4o/pId1XmoFAUCwzmaWyafn1x5CfrP5mv+Vj/clKTK+2e+B0UqQWko5QBrMaAH BKr+6+y58GTIck7CSGLxb2VIEW28Bp18aq+p1Xjm/Pzs6FsqEJ/PkUTiy3ZWcAUzS/GF CHlvJsKabB3czEjXzhz7SjQt9HvNSB4x1+uVPHy3rsiig34tMevcdD6YUqQbefyrSMGQ uobTYK308PjsL1ZCWzXHXrAfV8NIJfi+fDtwly+EIPkhRD+btp8WoIRiYs5wNaRmxao2 d6vk5wKyp0lipSlSDNkM7vNUXK8vtO418cL+WMvGccImo+pzuxk+9gHCbZ4ndzbZynOf jE3A==
MIME-Version: 1.0
References: <CAAoGPJzdYcCDB=J4ZdfDq1xwLYvZBmT1rC937xHjMd8vseZ-=A AT mail DOT gmail DOT com>
In-Reply-To: <CAAoGPJzdYcCDB=J4ZdfDq1xwLYvZBmT1rC937xHjMd8vseZ-=A@mail.gmail.com>
From: Doug Henderson <djndnbvg AT gmail DOT com>
Date: Fri, 22 Feb 2019 23:35:15 -0700
Message-ID: <CAJ1FpuNpWPsPowCOR=XNSzH0b3bTWBiKKLzXkrMmOpBF5_Q+Bg@mail.gmail.com>
Subject: Re: problem with mmap and fork()
To: cygwin <cygwin AT cygwin DOT com>
X-IsSubscribed: yes

On Fri, 22 Feb 2019 at 17:01, Glyn Gowing <> wrote:
> 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

> 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.

The problem is not with mmap() and fork(). The problem is with using
both fork() and pthread_mutex_*().

In Linux, and cygwin, the pthread_mutex appears to be a pointer to a
queue (maybe) located in writable (or copy-on-write) memory which
seems not to be shared between processes. This memory is common to all
pthreads (in each process), so pthread_mutex's will work for them, but
pthreads in another process will be using a different mutex.

Darwin (the mac's OS) is derived from NeXTSTEP, BSD, Mach, and other
free software projects, so it's implementation of pthreads may be
vastly or subtly different than the Linux and cygwin version,
resulting in different behaviour.

The "pthread_mutex_t" you create in shared memory, is just a pointer
(think a HANDLE) to the actual mutex data structure. I think you would
see identical results if the mutex was created in non-shared memory.

Search for "fork and pthread" on e.g. Google, to see some info about
mixing these features, and about the recommendations to use semaphores
for creating critical sections between processes vs using mutexes
between pthreads.

HTH
Doug
-- 
Doug Henderson, Calgary, Alberta, Canada - from gmail.com

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019