9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] does qlock(2) block all threads on a proc?
Date: Fri, 10 Aug 2007 12:30:18 -0400	[thread overview]
Message-ID: <cb7eb5e2c9837349aba5efee4ba5a7ab@quanstro.net> (raw)
In-Reply-To: <8ccc8ba40708100916o5bdf7c3eof067224764c06fd0@mail.gmail.com>

> The difference wrt lock/unlock is that it does not spin.  If the lock
> cannot be set, the
> thread is put to sleep in queue waiting for the lock. So, it's better
> to use qlock in
> general than it is to use lock. (IIRC, lock is used to protect the
> data structure of the QLock,
> that might give you more insight regarding the difference b/w qlock and lock).

pardon my pedantic streak.  but i don't think that classifying one
type of lock as "better" helps straighten things out.  one selects 
the right lock for the job.

in some cases, going to sleep is not an option.  in some cases
frequency of access makes qlocks impractical.  if you don't have 
a process (like in an interrupt context), you can't qlock.

*all locks spin*.  the difference between a qlock and a normal lock
is that an outer lock protects the inner lock.  a qlock will spin
aquiring the outer lock.  if the inner lock is locked, qlock places
the calling proc on the queue of waiters, releases the lock and
"waits" for its turn.  what wait means depends on the context.
the easiest code to follow is in /sys/src/9/port/qlock.c.  userland
qlocks slightly differently.

- erik


  reply	other threads:[~2007-08-10 16:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-10  0:14 david jeannot
2007-08-10  0:26 ` Kris Maglione
2007-08-10  1:56 ` erik quanstrom
2007-08-10 16:16 ` Francisco J Ballesteros
2007-08-10 16:30   ` erik quanstrom [this message]
2007-08-10 18:37     ` Francisco J Ballesteros

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=cb7eb5e2c9837349aba5efee4ba5a7ab@quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@cse.psu.edu \
    /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 NNTP newsgroup(s).