4 ms·
I’m stunned that this article exists and was published by Microsoft. Unsafe access to either is clearly undefined behavior. Discussing which one is more or less
by moregrist 3y ago
I’m stunned that this article exists and was published by Microsoft. Unsafe access to either is clearly undefined behavior. Discussing which one is more or less undefined is like discussing whether it’s safer to run with scissors or a knife: it doesn’t really matter because you’re going to cut yourself badly and possibly in life-changing ways.
Please protect your STL data structures with a mutex. Please keep your thread communications sane. There’s no reason to think through why one is more prone to explosion than another; any conclusions you draw are at best only relevant to your current compiler and STL implementation, and maybe only during some phases of the moon.
- aidenn0 3y agoIt's like discussing if you have a better chance surviving against a Tiger or a Lion when armed with a machete. I'm not jumping into the arena with either one, but it can still make for good conversation.
- pinum 3y ago"The customer understood that their code was broken either way. They just were curious why unordered_map seems to demonstrate the problem more clearly." Seems reasonable to me. It's an interesting question even if any given answer is only valid under narrow conditions.
- yalok 3y agoWhy stunned? The author reiterates 2 times that neither maps should be used in unsafe way. Look at this from the point of code analysis - if "a bit more thread-safe" map is used - you have less chances to detect the problem in local testing & and may be surprised in prod. And, you may be even more surprised when switching to unordered map. Usually, any big app has a huge tail of very rare crashes that nobody has time to fix, ever. Those rare crashes are indistinguishable from some system/hardware related faults (system OOM, system trying to kill an app, battery dying, bit flipping due to radiation/faulty silicon). And that's the point - if you are planning to change map to unordered map - look at the crashes list around map invocations and try to understand, if any of them are due to multithreading and not system/hw...
- yellowstuff 3y agoClearly the author should have stated a third time not to violate thread safety, to prevent the article from being misinterpreted.
- deleted 3y ago[deleted]
- btilly 3y agoThis is essentially a personal blog of a long-term Microsoft employee on all sorts of interesting technical topics. It isn't an official Microsoft publication.
- ironman1478 3y agoThe article isn't an endorsement of using thread unsafe structures without protection in a multithreaded context. It's simply analyzing why the bug was less prevalent with one data structure vs. another. It's an interesting question.
- fragmede 3y agoOne of today's lucky 10,000! Raymond Chen is a gem. His blog has many good features, I'll let you discover then for yourself. https://xkcd.com/1053/ https://xkcd.com/1053/
- pests 3y agoRaymond Chen has been at Microsoft since 92 on the shell team and has worked on OS/2, Windows 95, DirectX and others but is more well known for his 2003 blog "The Old New Thing" which does nerdy deep dives into the internals of Windows / Microsoft-verse and the various ways customers abuse it. Have you ever wondered what’s up with the CF_SYLK and CF_DIF clipboard formats? [0] Or why did the message on the Start menu change from Start to Ship It! for one build? [1] Or how about filling in some gaps in the story of Space Cadet Pinball on 64-bit Windows [2] [0] https://devblogs.microsoft.com/oldnewthing/20200226-00/?p=103489 https://devblogs.microsoft.com/oldnewthing/20200226-00/?p=10... [1] https://devblogs.microsoft.com/oldnewthing/20200505-00/?p=103727 https://devblogs.microsoft.com/oldnewthing/20200505-00/?p=10... [2] https://devblogs.microsoft.com/oldnewthing/20220106-00/?p=106122 https://devblogs.microsoft.com/oldnewthing/20220106-00/?p=10...
- userbinator 3y agoThe counterargument to the IMHO highly destructive attitude of "learned ignorance" that you're espousing is easily summed up in one sentence: "If you don't break anything, you'll never learn how to fix anything." Asking and answering "why" is an important educational process. I've met other developers like you, and quite frankly they've always been mediocre to abysmal in their work, especially when debugging, because they've almost completely lost the ability to reason and hypothesise.
- Voultapher 3y agoFrom my experience there is a real issue of C and C++ developers treating undefined behavior as an error. Yet you can't reason around undefined behavior, you can't catch it at runtime and there are more ways how UB is meaningfully different than an error or bug in the program logic. I can see how such a post could inadvertently reinforce such a mindset. No clue if the person you are responding to had that in mind.