Why did InterlockedIncrement/Decrement only return result’s sign? (2004)
devblogs.microsoft.com
devblogs.microsoft.com
EDIT: That said you do have to worry about being interrupted mid-sequence of instructions and data races but that's what critical sections are for. So INC or DEC (which increment/decrement and set flags) are perfectly safe under interrupts. If you have more a more complex sequence then you need a critical section. However they are not safe (without the LOCK) under multi-processing.
EDIT2: also to clarify you're not interrupted mid-instruction. I.e. you can't observe the undelying read/modify/write through interrupts, only through a second core/processor.
EDIT: if your point was that you can't return the value using either LOCK INC or INC and either on a single core or multiple cores then your point is correct. I sort of read it as INC itself (the x86 instruction) is racy under multi-threading.
Here’s what you might be missing: Even on a single processor machine, if you have multiple threads and a preemptive (!) multitasking OS like Windows 95, any locking protocol can be interrupted mid-sequence. A second OS thread (yes, they existed) may be scheduled and observe an inconsistent state. Or it may perform an update on its own and leave the first state in an inconsistent state when it resumes.
And yes, this kind of stuff actually happened.
EDIT: I was basically saying the comment above that was correct because the comment I was replying to seemed to suggest it wasn't. But I guess both of them are correct and we're all in agreement ;)
EDIT2: So really I agree that InterlockedIncrement/Decerement were designed for multi-processing use case since they basically offer no advantage for a single core over just inc/dec (++/--) this is what the comment above the one I was replying to (gp?) was implying and the person responding to that seemed to think otherwise ;) but I think we still found out we all agree.
It was fairly common to attach z80's and the like as secondary co-processors, as well as allowing peripheral boards direct access to RAM/etc via DMA. So, while I'm not aware of anyone building a machine using multiple 8086's its was pretty common to put 8086's and z80's together in the same machine, nevermind the 8087 was effectively a second processor as well until it was integrated in the 80486 DX.
Although looking at a few of the schematics on http://www.s100computers.com/index.html I don't see anyone actually using the 8086 #LOCK pin even if they are running the processor in max mode to gain the extra control lines for the S-100. Probably because few people were thinking about full _symetric_ Multi Processing, vs heterogeneous machines, which were fairly common. Z80 boards existed for a lot of machines (I had one for my apple II+), as did various other combinations.
https://web.archive.org/web/20190201150607/http://blogs.msdn...
Chen seems to be using it confidently, and it's clearly there in the names of the API entry points. Is this just something Microsoft made up? It's the first I've noticed it.
I disagree on that front. Mutex kernel objects have existed just as long as critical sections. Critical section objects are cheaper because they don’t switch into the kernel when not contended.
A pthread mutex on Linux won't enter the kernel when uncontended (thanks to futex -- this wasn't true ~20 years ago).
I would say the terms are pretty synonymous, and implementation choices differ; sometimes implementation choices are implied by the name but I don't think everybody agrees on how those choices map to names.
-- https://en.wiktionary.org/wiki/interlock#Noun
Which seems weirdly fitting considering the Win98 behavior on 80386 CPUs ;)
Further googling leads me to believe that MS indeed made the term up for referring to atomic operations back then, but they kept it ever since.
> On the CDC CYBER, an interlock register is available ... Operation of this interlock register is similar to TEST AND SET
Concurrency in Operating Systems, October 1976 https://www.computer.org/csdl/magazine/co/1976/10/01647182/1...
https://web.archive.org/web/19990420193302/http://microsoft....
I'm honestly curious, was it ever useful, or is it just an expression?
[1] https://en.wikipedia.org/wiki/Parity_bit
[2] https://12ft.io/proxy?q=https%3A%2F%2Fwww.hackster.io%2FMayu...
Let’s say you really only cared about the sign of the result — freeing a resource when a refcount reaches 0 is a plausible use-case for that. But instead of using a single CPU instruction, you decide to link in a Windows function, because it’s easy, and why not pay for the overhead of a dynamically linked function call when CPUs are so fast?
And the joke is, when users upgraded to Windows 98, your program became a lot slower, because without asking you, the API was augmented to emulate a CPU feature you don’t need.
If this isn’t essentially 1995’s left-pad, I don’t know what would qualify.
Very few programs ran on non-x86 back then anyway. Some people used to argue that writing assembly is more portable than using OS functions. I’m not saying I fully agree with that view, but it’s a discussion one can reasonably have.
(BTW, this is exactly the kind of argument people made in defense of left-pad, which in my view completely validates my analogy.)
I ended up in something similar with a prog I was working on. I had used some pre-release APIs. By the time they shipped win95 those APIs no longer existed, docs removed and the items purged from the headers. I did not have the luxury of calling someone in MS and saying 'fix that'.
The win16 way was to dig and bend it, mangle, until it worked. The win32 way was a bit lest flexible.