X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A157D385B513 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1676559595; bh=vhTTOZQy5DuciuObbbLWxoB4o4syP2TFELZMkrNj8Eg=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=EJjnoBVoS2Re2uhXEKUo2r35XMHspYDcjmTvAaw85Ar/rBjGWh74ciSVhwpaw+kNY XPjqETfnHF81PrlK7R/qRN7NHy/kCXNX2BzSJqpOa/tfpUqTmdEviVO3K7egYshpJe 7khKEgsnFZlzlFZiLc0Qh+NmpH5AjxnUSlpWdDco= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com Date: Thu, 16 Feb 2023 15:59:36 +0100 To: Yeo Kai Wei Subject: Re: [QUERY] Help With Semaphore Error on Windows : Cygwin Message-ID: Mail-Followup-To: Yeo Kai Wei , cygwin AT cygwin DOT com References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:c0OBZENpvnD8inteaGj1EeJQ067jwcaArRAEjKyRcJFa4qq85re Caf+8QT3ItyLyGMLUpWQCfAQ9wCbFNHYvLWWZ3PyOgytPAC0XkBucdB4YEr5JVONYG7ioJw wPTfcJBjuBZOxIuYbZycumnz2+A96sFBl5M8XHnP1hkd0kCyU7aFFVQiPsv4nyNkm+h+k9h Xex8gF2Z/yknmEZldRI3A== UI-OutboundReport: notjunk:1;M01:P0:AO3lHMIcZBw=;F89DVsy6Swf3yeqgsI9NOTMki6c 1cRvq0Ht6WgxTysFXNCNixJH5/9WGQHdjkrbhXaJRJJyRoIFPQhK+Pw/wKuCLj34NkbQbIS1h TPqo3WERJ6/ZcIkdJqq9rNoEWX8tqcR5+1zHx4qe9qewdvU3RMIumkEiN+NbFGBsymmssJdIk 1X4o61uy8R8Z49K5gRrgUTXPM5e66lDihPa7MDmH+mt/XOJ8wMa8FoK7vA110Fc1Bf1nFLud/ +Q02ZZVc1oZzHF4Xd+7VLcBYPvSZ1/ahcSN7b5xP5SdhZsmYcfSz31EG3x0dBm5TR22qRl/Sy ZXcmmJ3kjSisoXKYiaT6qG5KzH92HQCvLmPaheLwka6oIVLHAZeahyYQjBxfyi/ICBF6kww07 XZXF+bzoCtuH7Fp2mvQUnA6s9V58Qeh9pCKuOLxYuXL0sruiuj110i+BqB+aiQIHYk7CLJYb9 JD0zcctL9qNG1XriUnzBjq7idmvqmo+C4y6b3R7j0BuRvnwwkJjw0q6O0SPjtoT/LQH5WjgAR hkh5B57WS9+vAaxfqR4INdMaCT0g6sJ4su3YxZbvQvPxNFXyxw/V4czeSsiMjVF0nx9kYk/0G fDHIhWCNDCDKg9v1o0enXoNY5RieVijr/mLVxPOB3E7nZQU34wN/vvH1CRRHhQz7tWnyQtX54 EnYChXVBOscuosdGodXCh9Ve/yI3z+fqTVfc9he5fA== X-Spam-Status: No, score=-97.4 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_FAIL, SPF_HELO_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Corinna Vinschen via Cygwin Reply-To: cygwin AT cygwin DOT com Cc: Corinna Vinschen , cygwin AT cygwin DOT com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Hi Kai, Apart from what Takashi already wrote, there's another bug in this code: On Feb 16 12:04, Yeo Kai Wei via Cygwin wrote: > #define ByteSize 512 > #define BackingFile "/shMemEx" > #define AccessPerms 0644 > #define SemaphoreName "mysemaphore" ^^^^^^^^^^^^ What Takashi wrote. The reason that you don't notice that sem_open actuially failed is... > //Create the semaphore > sem_t* semptr = sem_open( SemaphoreName,//name > O_CREAT, //create semaphore > AccessPerms, //protection permissions > 0); //Initial value > > //ERROR > if(semptr == (void*) -1) ^^^^^^^^^^ This. Why do you test for -1? If you read the POSIX man page for sem_open, you'll see this: Upon successful completion, the sem_open() function shall return the address of the semaphore. Otherwise, it shall return a value of SEM_FAILED [...] ^^^^^^^^^^ SEM_FAILED is not necessarily -1. On Cygwin it's defined as #define SEM_FAILED ((sem_t *) 0) in /usr/include/semaphore.h. So your code just seems to fail in sem_post, but actually that's because sem_open failed and your code checks for the wrong return value. HTH, Corinna -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple