delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/10/09/09:54:20

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Tue, 9 Oct 2012 15:53:43 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: No support for sharing unnamed semaphores between processes through shared memory?
Message-ID: <20121009135343.GA19244@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <CALom-kwFp1EAfb4g5fqB6xrPR8Cak+3jSrr289mgao1B9U7HOw AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CALom-kwFp1EAfb4g5fqB6xrPR8Cak+3jSrr289mgao1B9U7HOw@mail.gmail.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT 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

On Sep 10 09:36, Matt Sexton wrote:
> Hello,
> 
> I am attempting to port to Cygwin an application that synchronizes
> between processes using unnamed semaphores in shared memory.  Both
> processes have mapped the shared memory region, one process
> initializes the semaphore, and both processes perform operations on
> it.  Under Cygwin, the second process, which does not initialize the
> semaphore, gets an EINVAL error when calling sem_post() on that
> semaphore.  (There is no race condition between the initialization and
> the posting of the semaphore by the different processes.)
> 
> Looking in /usr/include/semaphore.h, it appears that a sem_t is
> typedef'ed as pointer to a struct.
> 
> In winsup/cygwin/thread.cc, semaphore::init appears to make the value
> of the semaphore the result of a new operation.  This step would seem
> to preclude the sharing the of the semaphore between processes, since
> the pointer is only valid in the address space of the first process.
> 
> Is there no support for sharing unnamed semaphores between processes
> using shared memory?  The man page under Linux documents this use case
> and does seem to imply that it is part of the POSIX standard.

No, this case isn't supported, unfortunately.  The implementation of
pthreads in Cygwin is rather old, quite convoluted, and could probably
need a major revamp to support all POSIX requirements.

> If the use case is not supported, what is the recommended work-around?
>  Named semaphores?

Named semaphors should work in your scenario.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

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