This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: Once again, I need a binary semaphore
- From: Grant Edwards <grant dot b dot edwards at gmail dot com>
- To: ecos-discuss at ecos dot sourceware dot org
- Date: Tue, 17 Mar 2015 14:47:18 +0000 (UTC)
- Subject: Re: Once again, I need a binary semaphore
- Authentication-results: sourceware.org; auth=none
- References: <me737v$ojs$1 at ger dot gmane dot org> <5507F21B dot 1000900 at zhaw dot ch> <me9dtq$e2m$1 at ger dot gmane dot org>
On 2015-03-17, Grant Edwards <grant.b.edwards@gmail.com> wrote:
> On 2015-03-17, lesc <lesc@zhaw.ch> 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