From: Grant Edwards <grant.b.edwards@gmail.com>
To: ecos-discuss@ecos.sourceware.org
Subject: [ECOS] Re: Once again, I need a binary semaphore
Date: Tue, 17 Mar 2015 14:47:00 -0000 [thread overview]
Message-ID: <me9epm$e2m$2@ger.gmane.org> (raw)
In-Reply-To: <me9dtq$e2m$1@ger.gmane.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
next prev parent reply other threads:[~2015-03-17 14:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-16 17:18 [ECOS] " Grant Edwards
2015-03-17 9:21 ` lesc
2015-03-17 14:33 ` [ECOS] " Grant Edwards
2015-03-17 14:47 ` Grant Edwards [this message]
2015-03-17 14:57 ` Frank Pagliughi
2015-03-17 15:19 ` Grant Edwards
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='me9epm$e2m$2@ger.gmane.org' \
--to=grant.b.edwards@gmail.com \
--cc=ecos-discuss@ecos.sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).