public inbox for
 help / color / mirror / Atom feed
From: Alexander Terekhov <>
To: Blanco Alejandro-EAB005 <>
Cc: "''"
Subject: Re: FW: sem_getvalue()
Date: Wed, 08 Sep 2004 19:59:00 -0000	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <31173C0B4EF5D611A021009027CB2CBD04EE2CC6@fl08exm04>

> if there are threads waiting on the semaphore

That's pretty useless info. Consider "fast" semaphore using "lock 
queue" (Linux folks reinvented "half-or-less" of this thing and 
proudly called it "a futex") address based parking interface with 
"waiters bit" maintained by its implementation:


      lock_queue_wait(&lock, 0) // wait if sem.value is zero


  uintptr_t lock_queue;
  IF atomic_increment_rel(lock_queue = &lock) > 0x80000000
    THEN lock_queue_wake(lock_queue, 1)

(try/timed operations omitted for brevity)

BTW, fast mutex:


    atomic_bit_test_set_ccacq(&lock, 1) 
      lock_queue_wait(&lock, 1) // wait if locked bit is set


  uintptr_t lock_queue;
  IF atomic_decrement_rel(lock_queue = &lock)
    THEN lock_queue_wake(lock_queue, 1) 

"ccacq" stands for acquire-but-with-"control condition"-hint
(to avoid redundant memory barrier(s) -- arch specific stuff).

"rel" is a classic release.


  reply	other threads:[~2004-09-08 19:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-08 18:59 Blanco Alejandro-EAB005
2004-09-08 19:59 ` Alexander Terekhov [this message]
2004-09-09  9:11 ` Ross Johnson
2004-09-08 20:17 Blanco Alejandro-EAB005
2004-09-08 20:34 ` Alexander Terekhov
2004-09-09 12:59 Blanco Alejandro-EAB005
2004-09-09 13:55 ` Alexander Terekhov
2004-09-09 14:12 Blanco Alejandro-EAB005
2004-09-09 14:26 ` Alexander Terekhov

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \

* 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).