From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14863 invoked by alias); 17 Mar 2015 14:47:34 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 14846 invoked by uid 89); 17 Mar 2015 14:47:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_FROM_URIBL_PCCC,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: plane.gmane.org Received: from plane.gmane.org (HELO plane.gmane.org) (80.91.229.3) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 17 Mar 2015 14:47:28 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YXsmC-0007vF-CF for ecos-discuss@ecos.sourceware.org; Tue, 17 Mar 2015 15:47:24 +0100 Received: from 67-130-15-94.dia.static.qwest.net ([67.130.15.94]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Mar 2015 15:47:24 +0100 Received: from grant.b.edwards by 67-130-15-94.dia.static.qwest.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Mar 2015 15:47:24 +0100 To: ecos-discuss@ecos.sourceware.org From: Grant Edwards Date: Tue, 17 Mar 2015 14:47:00 -0000 Message-ID: References: <5507F21B.1000900@zhaw.ch> User-Agent: slrn/1.0.1 (Linux) X-IsSubscribed: yes Subject: [ECOS] Re: Once again, I need a binary semaphore X-SW-Source: 2015-03/txt/msg00004.txt.bz2 On 2015-03-17, Grant Edwards wrote: > On 2015-03-17, lesc wrote: >> >> >> On 16.03.2015 18:17, Grant Edwards wrote: >>> Once again, I find I need a binary semaphore for a C application I'm >>> porting from another OS. > >> And just using a mutex is not a option? (Sorry if you allready ruled >> that out, but you didn't metion why youd need that specific >> sync-mechanism). > > The Semaphore is used so that one thread can wait for completion of a > task that was farmed out to different thread: Thread A waits on the > semaphore until thread B posts. It's an inter-thread signalling > mechanism, not a mutual-exclusion mechansim. Perhaps I should be a bit more detailed: a Mutex is owned by the thread that calls cyg_mytex_lock(), and it can't be unlocked by a different thread. This enforcement of ownership prevents a mutex from being used in place of a binary semaphore for inter-thread signalling. I've run across situations in the past where I needed to use a semaphore for mutual exclusion, but a counting semaphore initialized to 1 works fine for that as long as you only release the resource once after acquiring it (not usually a problem). -- Grant Edwards grant.b.edwards Yow! World War III? at No thanks! gmail.com -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss