Skip site navigation (1)Skip section navigation (2)
Date:      Sat,  8 Jul 2000 18:13:38 -0700 (PDT)
From:      hsu@FreeBSD.ORG (Jeffrey Hsu)
To:        jdp@FreeBSD.ORG
Cc:        freebsd-arch@FreeBSD.ORG
Subject:   yield(2) (was Re: cvs commit: src/libexec/rtld-elf rtld.c rtld.h lockdflt.c)
Message-ID:  <20000709011338.880E337BA97@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
  Spinlocks are the only kinds of locks that work with all thread
  packages.  But on uniprocessor systems they can be inefficient,
  because while a contender for the lock is spinning the holder of the
  lock cannot make any progress toward releasing it.  To alleviate
  this disadvantage I have borrowed a trick from Sleepycat's Berkeley
  DB implementation.  When spinning for a lock, the requester does a
  nanosleep() call for 1 usec. each time around the loop.  This will
  generally yield the CPU to other threads, allowing the lock holder
  to finish its business and release the lock.

What do you think of adding a real yield(2) system call?  I do the
nanosleep too in some locking code I use for a pre-forked server (like
Apache), but I am unhappy with that.  I chosed 100ms as the sleep time
because that's one scheduler quantum (or used to be).  It wasn't clear
to me that a nanosleep of anything less than a quantum would guarantee
a yield.

							Jeffrey


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000709011338.880E337BA97>