Re: Macros for Spinlocks, Mutexes, Semaphores, etc




Chewy...@xxxxxxxxxxxxxxxx wrote:
>
> For my own OS...
>
> Essentially I want to add 'spinlock', 'mutex' and 'semaphore' type
> keywords to B0 (the language I am working on), for OS development work.

It's expensive (get it used!), but I'd suggest grabbing a copy of this:

http://www.amazon.com/exec/obidos/tg/detail/-/0471694665/qid=1125975976/sr=1-1/ref=sr_1_1/104-8961450-1232737?v=glance&s=books



> PS. For most OS's wouldn't the following be appropriate for threaded
> apps:
>
> ; Spinlock:

No, spinlocks are reasonable only in a few places, such as in interrupt
handlers and other kernel routines where blocking is not reasonable.
Applications should almost always block, not spinlock. Mutexes,
semphores, events, and monitors (as provided by the OS) generally put a
thread or process on a queue until the event that they are waiting for
occurs (that is, the thread/process is *blocked*) and then puts them
back on the run queue when the thing they are waiting on occurs.

Cheers,
Randy Hyde

.



Relevant Pages

  • Re: 2.6.15rc5git1 cfq related spinlock bad magic
    ... I may have also been experimenting at the time with Pete Zaitcev's ... If CFQ is around, it keeps the queue pinned and uses ... > spinlock located in its data structure, ...
    (Linux-Kernel)
  • Re: 2.6.15rc5git1 cfq related spinlock bad magic
    ... I may have also been experimenting at the time with Pete Zaitcev's ... it only decrements its refcount. ... it keeps the queue pinned and uses the queue's spinlock. ...
    (Linux-Kernel)
  • Re: [patch] generic rwsems
    ... think your suggestion to instead move everyone to the spinlock version ... for the slowpath. ... extra flag in the counter to indicate there's stuff waiting on the queue, ... Note that the contention flag may only be set or cleared in the slow path ...
    (Linux-Kernel)
  • Re: When its okay to wait
    ... Kernel wait functions use internal spinlock to set/check wait objects ... <BubbaGump> ... Waiting by itself doesn't prohibit overlapped I/O. ... Atomicity requires waiting, even if for a short period of ...
    (microsoft.public.development.device.drivers)
  • Re: Never seen a driver that uses a KSEMAPHORE ???
    ... mechanism to handle serialized access to a cancel-safe IRP queue. ... I think that these queues are usually protected by spinlock. ... CsqReleaseLock routines themselves. ...
    (microsoft.public.development.device.drivers)