public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Grant Edwards <grante@visi.com>
To: Nick Garnett <nickg@cygnus.co.uk>
Cc: ecos-discuss@sourceware.cygnus.com
Subject: Re: [ECOS] No binary semaphore in C API?
Date: Mon, 26 Mar 2001 11:37:00 -0000	[thread overview]
Message-ID: <20010326133727.A3008@visi.com> (raw)
In-Reply-To: <wwghf0glpyc.fsf@balti.cambridge.redhat.com>

On Mon, Mar 26, 2001 at 12:39:07PM +0100, Nick Garnett wrote:

> > > Is there a technical reason that there isn't a C API for binary
> > > semaphores, or is it something that just hasn't been done yet?
> > 
> > Certainly no technical reason. Nick may not have done it out of
> > principle. But right now he's on vacation, so it's best to wait
> > till he returns.
> 
> It was never intended that the KAPI be a complete reflection of
> the kernel implementation. It is meant to be a consistent,
> self-contained, small API that can be used by C applications.
> Like the uITRON and POSIX APIs it only exposes a subset. It was
> considered unnecessary to export binary semaphores,

Why impliment binary semaphores if there is no intent to
allow their use?

> since a counting semaphore initialized to 1 is functionally
> equivalent.

Not quite.  There are sequences of wait()/post() that will not
give the same results for an boolean and integer semaphore.

        Task 1                Task 2
        ------                ------
          [semaphore value == 1]
        wait()
        post()
        post()
        wait()                wait()

At this point, only one of the tasks is runnable with binary
semaphores, but both are runnable with a counting semaphore.

Admittedly, multiple posts is probably a bug if you intend the
semaphore to be used for mutual exclusion, but using a binary
semaphore protects you from such bugs.

-- 
Grant Edwards
grante@visi.com

  parent reply	other threads:[~2001-03-26 11:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-16 12:01 Grant Edwards
2001-03-19 13:42 ` Jonathan Larmour
2001-03-26  3:53   ` Nick Garnett
2001-03-26  7:12     ` Fabrice Gautier
2001-03-26 11:37     ` Grant Edwards [this message]
2001-03-27  2:00       ` Nick Garnett
2001-03-27  5:32         ` Grant Edwards
2001-03-28  5:29         ` Bart Veer
2001-03-28  6:45           ` Sergei Organov
2001-03-28  7:38             ` Grant Edwards
2001-03-28  7:39             ` Bart Veer
2001-03-28 10:01               ` Jonathan Larmour
2001-03-28 10:01               ` Sergei Organov
2001-03-28 11:05                 ` Grant Edwards
2001-03-29 11:51                   ` Sergei Organov
2001-03-29 11:49                     ` Grant Edwards
2001-03-29 11:55           ` Chris Gray
2001-03-29 19:33             ` Bart Veer
2001-03-29 20:50               ` Grant Edwards
2001-03-30  2:22               ` Sergei Organov
2001-03-30  6:54                 ` Grant Edwards
2001-03-30  7:42                   ` Sergei Organov
2001-03-30  5:39 Rosimildo daSilva

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=20010326133727.A3008@visi.com \
    --to=grante@visi.com \
    --cc=ecos-discuss@sourceware.cygnus.com \
    --cc=nickg@cygnus.co.uk \
    /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).