9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Francisco J Ballesteros" <nemo@lsub.org>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] does qlock(2) block all threads on a proc?
Date: Fri, 10 Aug 2007 20:37:22 +0200	[thread overview]
Message-ID: <8ccc8ba40708101137u7a7903f6v6ee7bdca7bfe3717@mail.gmail.com> (raw)
In-Reply-To: <cb7eb5e2c9837349aba5efee4ba5a7ab@quanstro.net>

(all the time thinking about using them from userland)

the point is that the tas lock is just used to secure the QLock struct, and it's
not likely that the Lock in the QLock would be set for too long. Thus, IMHO
it's better just to use qlocks so your thread gets out of the way until it could
get the lock. Again, I'm referring to user programs using the thread library.

In the kernel, it depends. But because of the mention of thread(2) in
the original
post,  I think the
question was about user programs using libthread.

On 8/10/07, erik quanstrom <quanstro@quanstro.net> wrote:
> > 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 18:37 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
2007-08-10 18:37     ` Francisco J Ballesteros [this message]

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=8ccc8ba40708101137u7a7903f6v6ee7bdca7bfe3717@mail.gmail.com \
    --to=nemo@lsub.org \
    --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).