From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71339 invoked by alias); 17 Mar 2015 14:57: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 71330 invoked by uid 89); 17 Mar 2015 14:57:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: vms173005pub.verizon.net Received: from vms173005pub.verizon.net (HELO vms173005pub.verizon.net) (206.46.173.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 17 Mar 2015 14:57:32 +0000 Received: from [192.168.0.5] ([72.93.35.36]) by vms173005.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0NLD00FCI2V6GM30@vms173005.mailsrvcs.net> for ecos-discuss@ecos.sourceware.org; Tue, 17 Mar 2015 09:57:12 -0500 (CDT) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=A7bb5BSD c=1 sm=1 tr=0 a=P6lJ2fsNxnPqIB/NfOSTCw==:117 a=cmpKiNEfRqcA:10 a=N659UExz7-8A:10 a=84BadPHTAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=emO1SXQWCLwA:10 a=pGLkceISAAAA:8 a=E58J1kW82_f8reZtDtMA:9 a=pILNOxqGKmIA:10 Message-id: <550840C2.8090900@mindspring.com> Date: Tue, 17 Mar 2015 14:57:00 -0000 From: Frank Pagliughi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-version: 1.0 To: Grant Edwards , ecos-discuss@ecos.sourceware.org References: <5507F21B.1000900@zhaw.ch> In-reply-to: Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit X-IsSubscribed: yes Subject: Re: [ECOS] Re: Once again, I need a binary semaphore X-SW-Source: 2015-03/txt/msg00005.txt.bz2 I'm in agreement, for what it's worth. I've had to make use of the binary semaphore through the C++ API, and it always made me wonder why it wasn't brought out to the public/C API. Why code up the exact same thing with a condition variable when there's a perfectly good binary semaphore in the OS? Frank On 03/17/2015 10:47 AM, Grant Edwards wrote: > 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). > -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss