Maybe we are having a terminology problem. “Should” does not mean “can’t”.
Spinlocks are software constructs. It is up to the implementation to decide
if, for example, it is going to refuse to honor a release request from
anyone except the current thread owner. The spinlock implementation in NT
does not enforce such a rule, consequently you can release a spinlock from a
non-owning thread. That does not mean that you should do that, it means that
you can do that but that doing so violates the contract, just as modifying
the object covered by the spinlock without holding that spinlock violates
the contract. An assertion was made that one can’t release a spinlock this
way, that assertion is wrong.
“a protocol that users of the mechanism have to adhere to” has approximately
the same meaning to me as “a contract”, so I fail to see any real difference
here.
Finally, another assertion was made (not by you) that one cannot block after
acquiring a spinlock. This is of course not true at all. A spinlock owning
thread is free to acquire another spinlock and will of course block waiting
for the current owner of that lock to release it. Once again perhaps we all
are just having a terminology problem, and that ‘block’ meant ‘wait on an
event’ in the poster’s terminology.
On Dec 23, 2007 2:11 AM, Alberto Moreira wrote:
> I’m not sure I follow you guys. If thread A grabs a lock, no other thread
> should be able to release it, or it’s not really a lock. But then, as you
> yourself have pointed out, the IRQL implementation is far from a
> straightfoward interrupt management, so, hey, everything’s possible.
>
> Synchronization constructs shouldn’t be regarded as contracts: they’re
> engines that should have highly predictable behavior. It’s the usage of
> synchronization constructs that may be regarded as a contract, and even
> then, the better the synchronization construct the less one has to treat
> it
> as a contract. For example, if I have a self-synchronizing object or data
> structure - also called a “Monitor” in computer science parlance -
> accesses
> to its data are synchronized as a matter of fact, by the object itself,
> contract or no contract. The mutual exclusion is enforced by the data
> itself, not by the users of the data. And that can permeate all the way to
> the language level, if you doubt it I invite you to read the Concurrent
> Pascal language spec.
>
> On the other hand, if you have a simple-minded construct such as a mutex
> or
> even a semaphore, there’s a protocol that users of the mechanism have to
> adhere to, otherwise synchronization is not going to work. But jot this
> one
> down to the weakness of the mechanism, not on the fact that its usage
> might
> or not require something like a “contract” among threads.
>
> As far as the OS goes, its duty is to implement the mechanism so that
> users
> can take advantage of it. I do not thing it’s an OS call to tell users
> what
> they can or cannot do, as long as applications use the mechanism through
> the
> OS’s published APIs. It is also not the OS’s call to tell drivers what
> they
> will or will not do with well published and well specified synchronization
> mechanisms, again, as long as drivers respect the API and use it properly.
> And, in a well designed OS drivers sit between the hardware and the OS.
> Hardware should be driven by drivers, not by the OS, and IMHO the OS has
> no
> business sitting between a driver and its hardware. OS’s aren’t the owners
> of the machine - they’re a service layer. An OS isn’t a ruler or a
> president, but a public servant that is at all times at the command of its
> users.
>
> If you want to shield the OS from driver problems you should begin by
> running them in different protection rings. I find it mind boggling that
> even though the i386 architecture implements such a large array of
> security
> oriented features, the OS uses none of them, all under the excuse of being
> compatible with machines that do not have nearly a fraction of that
> functionality. Go figure!
>
>
> Alberto.
>
>
>
> ----- Original Message -----
> From: “Don Burn”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Saturday, December 22, 2007 6:10 PM
> Subject: Re:[ntdev] Are callbacks guaranteed to run consecutively?
>
>
> > As Mark Roddy pointed out, a thread on a second processor could release
> > the lock. You seem to be thinking uni-processoor which shows a great
> gap
> > in thinking about synchronization. By the way, there have been many
> > spin-lock implementations that do not block scheduling, many of them
> test
> > the spinlock n times, and if they do not get it yield. As far as IRQL
> > remember this is a Windows (and I think VMS concept), it is definitely
> not
> > a generic OS concept.
> >
> > Every synchronization mechanism is a contract, if you violate the
> contract
> > you fail. Saying something is not a sync mechanism just because you
> don’t
> > like the contract, is just garbage tha same as saying that the OS does
> not
> > have the right to dictate what your driver can do. Perhaps you can get
> > away with it some time, but sooner or later people catch on to bad code,
> > or stupid claims.
> >
> >
> > –
> > Don Burn (MVP, Windows DDK)
> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > Website: http://www.windrvr.com
> > Blog: http://msmvps.com/blogs/WinDrvr
> > Remove StopSpam to reply
> >
> >
> >
> > wrote in message news:xxxxx@ntdev…
> >> Don,
> >>
> >>> By your definition SPINLOCKS do not nessecarily synchronize, since one
> >>> thread can
> >>> decide to release a spinlock that another took,
> >>
> >> How on Earth may something like that possibly happen??? If thread X
> >> takes a spinlock, no other thread should have a chance to run on a
> given
> >> CPU until spinlock gets released. This is why spinlock holders always
> run
> >> at elevated IRQL. This is not just some implementation feature, but,
> >> instead, just a conceptual thing - if context switches were possible
> >> while spinlock is being held, it would make the very concept of a
> >> spinlock unworkable…
> >>
> >>
> >>> Callbacks have been a synchronization mechanism long before windows.
> >>
> >> …but only on uniprocessor systems (that were prevalent at the time)
> >>
> >> Anton Bassov
> >>
> >
> >
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > For our schedule of WDF, WDM, debugging and other seminars visit:
> > http://www.osr.com/seminars
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
–
Mark Roddy