The first such algorithm w/o hardware assist was by Dekker…
It reminds us, how the things shaped up over the years and there were defining moments to define the requirements, and then amendment(s) to it…
For a lock, initially : Mutual exclusion, deadlock free, and free of starvation. Then came the fairness which is a part of starvation, but somewhat more assertive. Hence came the queued locks.
Another one is like: Overlay, segmentation, sharing, paging… Lot of it started in software, then lands in hardware !
-pro
Date: Sat, 12 Oct 2013 02:10:44 -0700
From: xxxxx@gmail.com
To: xxxxx@lists.osr.com
CC: xxxxx@lists.osr.com
Subject: RE:[ntdev] How does InterlockedExchange work
The following algorithm is dated 1981 but seems to satisfy the requirements without any hardware assisted synchronization (memory reordering notwithstanding).
http://en.m.wikipedia.org/wiki/Peterson’s_algorithm
On Sat, Oct 12, 2013 at 6:37 AM, xxxxx@flounder.com wrote:
In the past, many architectures supported what was called
“read-pause-write”, the equivalent of LOCK, on certain instructions. For
example, on the PDP-11 (and, consequently, almost certainly on the VAX),
INC and DEC were always done with read-pause-write. The problem with this
it that it wastes memory bandwidth, hence the optional LOCK prefix on the
x86 family. It is also nice that the LOCK prefix can apply to many
different instructions.
There is no such thing as a “lock free” algorithm, although some limited
cases (a circular buffer accessed by at most two threads comes to mind)
can be made to work without explicit locking. However, like the “locked
access” example we had to do in Algol, an algorithm that requires
simultaneous access must have some known invariant. The circular buffer
case usually works because the “head” is accessed by exactly one thread
and the “tail” is accessed by exactly one thread, meaning that locking was
not needed. But the number of “lock-free” algorithms I’ve seen always
seem to depend at some level on instruction atomicity, or are so
incredibly fragile that attempts to adopt them usually lead to some error
that invalidates the complex set of preconditions that make them work.
And all too often, it is an attempt to generalize a two-thread-safe model
to an N-thread-safe model. I’ve seen a few of these spectacular failures,
caused by people who felt that those synchronization primitives like spin
locks, mutexes, and semaphores were “too complicated” and they had a
“simple solution”. Yeah, right.
joe
>> IMHO this paradigm is erroneously called ‘lock free’, but really is is
>> hardware lock based instead
>> of software lock based.
>
> In order to realize how erroneous calling these functions lock-free is you
> just have to keep in mind that
> not all architectures that support MP provide the exhaustive sets of
> operations that may use bus locking.
> Don’t forget that on many architectures (they are known as load-and-store
> ones) you cannot perform arithmetic and logic operations directly on
> memory operands - instead, you have to load operands to registers,
> perform an operation in registers, and then store the results in memory.
>
>
> It is (hopefully) obvious that you cannot implement functions like
> InterlockedIncrement() on such an architecture like that in one go,
> because ‘LOCK INC [.memory]’ -like operation is obviously impossible on
> it. Instead, you have to, first, obtain a test-and-set-based lock, then
> update the target variable, and then release the lock…
>
>
>
> Anton Bassov
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
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
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
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