X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FD8238555A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1676609812; bh=Ea5aWxWHJgNAebA1umBPc5lWTimvpg6Ux38F5GeclcI=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GOfdjb419AKxjCvWyDn2oxsQ0gFkuR80uXW3WdUoDIckeH92I0ftUeYeksqijnVKs 0/nfGx8tMytSsRPGpq3f7eFg3PnlvPxjQUsK2PQsyYwvpB44xHMFiqjxFY1aDxwkyL qA1ZwPz/tawmszU9DvNzNd60Moq26kf60YcBqHZc= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 061573858D33 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FO5QdmK87WChlqioQTENHwoVp1w27lRw89bUAwh/yA098S+Spu0MZFsILomqIe3OsotMXqipHlGsgcewh6Et5qnH+HDuxF1sW9+Dcx2+10eA2tulRfrsrNMC/jiMKKJJUoHF9+7Lx35bazlch6qZviIIgXlZOBNHT7F2tG8uWQT4CRyD0dvO/pmfa2FSHV/IReEKqvml/fnXsUHMlWZ5EzDM7YpenQ31oePIqmhuy9QJytRvjco1RrzV+jrHzCvsOvXuXHwhAr48dTwrYwtGqH8LsXoEjv5w3oIHornTVFUJUKTkxe4HBi8/LCWTH+BrHtJ1nZmV/6/ooJT6bDyqbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G8k8jLGXM01FMfWW+I5o8cjP70WOtWiifGa7JXxeHLs=; b=AsJBY1qRwCKgCKtuGaEa38HyVjQ4V3AMXlU89K6PYMk43Y3cRBJMIah6S8vaSqYncGgbRXoY9iImdy8FOlYHkQliD2sXGWQxLKJOyp0xW3ZTvmiIwS1hK/itlOu6g7/+FNiklQMXjigKKbJnuwociXo3I5dw+POhIPRg7knpy7VGoF8uMbHgJSsebKyLeoYL4jGW1jK6hM7Ls7nLNkgmOE7p7KrW0LNdJeyoau7bg1ry+VzMYh0ja+e4FIuvrMjTC2y4HTP4sGS3TfdGAWot3q07JzTdpRG1vUUmKCNjcKD28edqL6cIGUZoqIQDpk9ZgoeKYB/2IPjXKZPxUi+RHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Message-ID: Date: Fri, 17 Feb 2023 12:56:06 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [QUERY] Help With Semaphore Error on Windows : Cygwin Content-Language: en-US To: cygwin AT cygwin DOT com References: In-Reply-To: X-TMN: [imtegnPVd/6AhVZNo2HbxpTdI0FUoOhex3xDI564sLU=] X-ClientProxiedBy: SI2PR04CA0010.apcprd04.prod.outlook.com (2603:1096:4:197::11) To PH0PR05MB9918.namprd05.prod.outlook.com (2603:10b6:510:299::5) X-Microsoft-Original-Message-ID: <3c487705-e17e-9069-d8d4-b083f9b84489 AT hotmail DOT com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR05MB9918:EE_|SJ0PR05MB7609:EE_ X-MS-Office365-Filtering-Correlation-Id: 159f5cf7-9b25-4d2d-900b-08db10a34a6e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: niJeIoQpK9KYKjT8LI5ESMIwqRCa6uZwqcFYOWxd4oaZZg6pIV9VtDecM7P1YMR8hVKfz91y4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VTFucFNra2tjcFVHb3o5dWFF?= =?utf-8?B?Y213NXh3Wk82cUtYUEh2ajlma3gxaEFSK0JtNWJYYlhseWxFZGg0MTR4QjFs?= =?utf-8?B?M0poZU9nLzl6Qmd2b0MrQ1JsUWd5U1hRYTVTUjNBZ09tblVLZCtjaTUvR0JU?= =?utf-8?B?ejlKMWJFYWh1WlFuL041RTNjTW1xaElqRktZekdpUDcvZlhDNlh0dWQ2bHFa?= =?utf-8?B?dnU1Tys5VlVaUEdERU5iZnVMNTdzZXNUSVpCZDlCSTBlVTJ2OWIyUlFFVFBQ?= =?utf-8?B?alFPL3ZSblI5ZE9JbCtMeTNYSzl3ZHozejlyZGt1cDEza0JFSXVrVmN0NlVI?= =?utf-8?B?VHNuZkhwNjZmeE50SE15bVdXSzdwNlk0TUQxUnpicGh4cklaS2VJbElnNjF6?= =?utf-8?B?VXlZRkZyWXNRMVZpK00wTUZlcUNhRllmZXY3d2NJRHZFNFJWbFlrZGI0Y0h3?= =?utf-8?B?NG5adk11aldiaXZTRmFDVXhrSkNiQmxkVVJMemVXWUozeHg0elFuTTFnPT0=?= X-OriginatorOrg: sct-15-20-4823-7-msonline-outlook-84f76.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 159f5cf7-9b25-4d2d-900b-08db10a34a6e X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB9918.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2023 04:56:12.3600 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR05MB7609 X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_MUA_MOZILLA, FREEMAIL_FROM, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no 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 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: Yeo Kai Wei via Cygwin Reply-To: Yeo Kai Wei Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "Cygwin" Hi All, Thanks for the help. It works now. So, the 2 things that were required 1. Adding the '/' in front of the semaphore name so that Cygwin can recognise it #define SemaphoreName "/mysemaphore" 2. Changing the if check from if(semptr == (void*) -1) to if(semptr == (sem_t*) 0) Thank you very much, Takashi and Corinna. Kind Regards, YEO Kai Wei On 16/2/2023 10:59 pm, Corinna Vinschen wrote: > 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