9 ms·
Why is Windows still tinkering with critical sections? – The Old New Thing
- jojomodding 1y agoHow is a critical section different from a lock?
- bitwize 1y agoIt's a kind of lock. Critsecs are faster and lighter weight than mutices (kinda like a futex), but cannot be shared between processes, only threads within a process. Mutices can be shared between processes but because of that they have to make syscalls every time they're locked or released.
- eterm 1y agoMutex isn't latin. The plural of mutex is mutexes.
- deleted 1y ago[deleted]
- verandaguy 1y agoIt’s a running joke in the field to have exotic pluralizations. Mutex->mutices is one, box->boxen (by analogy to oxen) is also pretty common. We need more casual light-heartedness in this line of work considering how much casual bullshit there is.
- zabzonk 1y ago> box->boxen (by analogy to oxen) is also pretty common. Not to mention (from way back when) VAX -> VAXen.
- hcs 1y ago> there's two hard problems in computer science: we only have one joke and it's not funny. https://news.ycombinator.com/item?id=42046226 https://news.ycombinator.com/item?id=42046226
- remix2000 1y agoExcept it actually is Latin. Both "mutual" and "exclusive" are borrowings from Latin.
- tialaramex 1y agoNo, it's an English word. The fact it's related, distantly, to some words in Latin doesn't mean mutex is Latin.
- remix2000 1y agoI'm pretty sure you could construct it in many other modern languages that have some Latin influence as well… So why do you think "index" is a Latin word and "mutex" isn't then?
- tialaramex 1y agoI don't think "index" is a Latin word? You're probably asking the wrong person, I am quite comfortable to say indexes, and indeed sheeps -- it's an English word I can just put the -S noise at the end to pluralize it and that'll be fine even if (as with ox) there is a special case rule that some people insist matters for this word or that one. Likewise I'm comfortable with "Can't nobody prove nothing", which I think is a succinct way to express an opinion that would be rather awkward when expressed in the prestige dialects of English instead.
- anticensor 1y agoplural of mutex is indeed exmut (exclusive mutation) :)
- nitwit005 1y agoThey gave the different sorts of locks different names. Locks usable across processes are mutexes, and locks only usable within a process are critical sections.
- Dwedit 1y agoDifferent names can be a huge source of confusion. The C++ standard library uses `std::mutex` as a lightweight synchronization lock. But on Win32, `Mutex` refers to a heavy kind of lock that can be used across processes. Very different things despite both using the same word "mutex" in the name. Here's another example of confusing terminology. In the C standard library, `fflush` just advances you to the next step, where your buffer goes out to the 'write file' system call, where your data sits in the disk cache to be written later on. Meanwhile, Win32's `FlushFileBuffers` actually forces everything out to the disk, acting much more like `fsync`. Yet again, very different things despite using the same word "flush" in the name.
- o11c 1y agoReally, the oddity is that Microsoft thinks there's a significant difference between in-process communication and cross-process communication. They're all running on the same physical memory and the kernel can share access to that.
- Dwedit 1y agoI mean you can put a critical section inside of shared memory, but the heavy mutex is used for situations where you need to actually name the mutex, then have another process open it by name. Example uses include preventing multiple instances of a single program from running. Not the kind of thing you'd use a std::mutex or critical section for.
- Dwedit 1y agonote: Do not actually put a critical section inside of shared memory. They allocate semaphores specific to one process.
- ajross 1y agoIt's just a lock. It's analogous to a pthread_mutex_t (which on Linux is a futex), where the operation in the uncontended case is a single atomic access to shared memory. The contended case needs to enter the kernel to suspend, or to make a decision about who to wake up, and that seems to be the subject of the blog post.
- the__alchemist 1y agoIn embedded (not sure how applicable here?) you invoke a critical section to access a lock. You will have an interrupt handler. Inside that, you will invoke a critical section, which prevents other processes from interrupting it. Inside the CS, you an get a handle to a mutex that has shared state. The mutex is what I would call the "lock" in this convention.
- TinkersW 1y agoCritical sections are very old, and bloated version of a mutex, but there isn't a good reason to use them today. Today you can use SRWLock or WaitOnAddress on Windows(or std::shared_mutex for portable impl, but not std::mutex because reasons).
- ack_complete 1y agoTo add to what others have said, additional characteristics of a Win32 critical section: - It is purely an in-process lock, and originally the main way of arbitrating access to shared memory within a process. - It is counted and can be recursively locked. - It defaults to simple blocking, but can also be configured to do some amount of spin-waiting before blocking. - CritSecs are registered in a global debug list that can be accessed by debuggers. WinDbg's !locks command can display all locked critical sections in a process and which threads have locked them. Originally in Win32, there were only two types of lock, the critical section for in-process locking, and the mutex for cross-process or named locks. Vista added the slim reader/writer lock, which is a much lighter weight, pointer-sized lock that uses the more modern wait-on-address approach to locking.
- wpollock 1y agoA critical section is code that accesses mutable shared data in a non-atomic way (i.e. as several steps, the classic example is: fetch data into a register, process that data, store the result back into memory). A lock is a mechanism that protects such data by preventing other code (or other threads running the same code) from accessing that data until the critical section completes. Locks come in several types. A developer picks one type depending on the use of the protected data; for example, exclusive, reader-writer, and others. Locks are great at preventing data corruption and data loss, but come with issues. They can hurt performance, can cause "liveness" and other issues, and are usually "advisory" ("mandatory" locks which are enforced by the OS are rarely available) so developers must remember to protect data by using locks around every critical section. Modern hardware includes support for many lock-free mechanisms that can greatly reduce the need for locks.
- jeffrallen 1y agoThis is hands down the worst Old New Thing he ever wrote. He either is, or at least should be, ashamed of the poor engineering his colleagues are doing, and trying weakly to defend them. Monkeying with critical sections is hard. Monkeying with them due to performance and memory optimization while maintaining correctness is incredibly hard. If they'd done a good job of it, no one would have noticed, and Raymond would have had a cool story to tell. Instead we got this. Sigh, Microsoft, what's happening over there?
- spookie 1y agoNever break user-space and all
- jofla_net 1y agoAfter a while that kool-aid, chilled to optimum temperature, on infinite tap, becomes an aqueous sanctuary, even the most staunch hold-outs cannot resist.
- wat10000 1y agoIf they’d done a good job, they wouldn’t have made a change that used a little more stack space and triggered an old bug where GTA used an uninitialized local variable? Huh?
- toast0 1y agoPerhaps not, but setting the compatability mode should maybe get programs that worked before to work again. Using extra stack space has got to be on a list of things likely to cause trouble.
- wat10000 1y agoSo adding a local variable to any function in the system needs to be considered dangerous, and have a way to run an old version of that function that doesn’t have a new local variable? How could that possibly be practical?
- twoodfin 1y agohn discussion of the GTA bug that triggered this post: https://news.ycombinator.com/item?id=43772311 https://news.ycombinator.com/item?id=43772311
- kchoudhu 1y agoGiven how awful performance on my Windows desktop is, I am shocked that Microsoft is still investing in performance.
- chongli 1y agoIt's really funny to me as well. All this effort put into low level performance seems like picking up pennies in front of a steamroller. The operating system (and core business software such as Office) is overflowing with bloat that absolutely tanks the performance and responsiveness of the system. On a fresh boot I might as well go for a 15 minute coffee break lest I end up with multiple hung applications blocked on the UI thread.
- xenophonf 1y agoIt's bad everywhere. Every time I've upgraded Ubuntu on my old laptop, performance gets worse and worse because more and more junk keeps getting added. Absolutely maddening.
- exe34 1y agomy nixos with just xmonad works really well, I haven't noticed any degradation in the last 10 years of updates.
- xenophonf 1y agoNixOS looks super cool, but it also looks too much like actual work. As a FreeBSD main for two decades, I've played that game already and have the (sadly, now long dead) tinderbox and poudriere installations to prove it.
- Scramblejams 1y agoIs it the desktop environment or background stuff that’s getting worse for you? If the former: FWIW I was pleasantly surprised when I switched back to Kubuntu. KDE’s surprisingly resource efficient these days, actually seems pretty close to XFCE.
- thw_9a83c 1y agoThis shows that having a legal way to run outdated operating systems is always important to guarantee that old software runs exactly as intended. Online activation schemes make this problematic. The solution seems to be installing and fully activating the operating system in the VM while it's still possible, then archiving the VM image. However, I don't know how reliable this method is, since the Windows OS may require reactivation if the hardware configuration changes significantly. Therefore, if the future VM host machine exposes slightly different hardware to the guest machine, the activation might be gone.
- benoau 1y agoHopefully the "Stop Killing Games" movement will create some formal obligations around those activation schemes too since it's pretty much the same problem from a different angle.
- layer8 1y agoThis particular example actually doesn’t show that. The misbehavior is caused by a bug in the original game, which was initially hidden only by pure chance, and was already fixed 20 years ago in updated releases of the game, and can be fixed in any version by adding the missing parameters in a plain-text asset (or running the existing patcher add-on). I agree in the general case, but this particular case isn’t a good argument for it.
- thw_9a83c 1y agoI would argue that this case also demonstrates the aforementioned problem. Apparently, an older version of the Windows OS was tolerant to this specific bug, and the game worked just fine. Future users might not be even aware that an updated release of the game fixed this bug, or they might not have access to the update. You can't blame the user for the fact that the old software contains something that is, technically, an invalid use of the API, meaning the software shouldn't have worked, even in the past. The only way to reliably make the old software work as intended is to have an OS version from that time available.
- 1y ago
- jofla_net 1y agoCriticisms of his post aside. Isn't it unfortunate, the absolute degree everything legacy is at least in some way tethered to windows. If only there had been an open alternative, it would allow huge communities to emerge keeping very old software/games working indefinitely. Not that linux was even remotely close to being usable even only twenty years ago. Relying on a giants benevolence is never going to work in the long run. Their contemporary direction is only a function of what side of the bed theyd like to turn on today.
- grishka 1y agoReactOS is a thing.
- ravenstine 1y agoAnd it's garbage. Every time I've tried it, from 2007 to now, it's been a buggy hunk of crap. I normally try not to disparage peoples software projects, but I really don't get ReactOS. I tried it again actually just a few weeks ago. It's barely usable. You'll have far fewer problems just using Wine with Linux.
- grishka 1y agoIt's been getting better lately. That's the thing with these kinds of projects that aim to run vast libraries of preexisting software — they're crap for a long, long time, until suddenly there's enough compatibility that hey, it's actually usable. The time vs usability graph for them is very non-linear. Wine was "garbage" for decades as well. For a long time, it wouldn't do a satisfactory job of running anything but simplest win32 apps. Same for Ruffle, the open source flash player, but it got to that point much quicker because the API surface is orders of magnitude smaller.
- bitwize 1y ago> Every time I've tried it, from 2007 to now, it's been a buggy hunk of crap. So, VERY much in keeping with Windows tradition, then!
- 1y ago
- 2OEH8eoCRo0 1y agoTask manager takes 5 seconds to open on Windows 11 now
- jmkni 1y agoRaymond Chen has such a unique style that I know it's going to be him before even clicking on the link