- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
TRWTF is thinking volatile has anything to do with multithreading.
Admin
if (Confuzzled.comment == "Comment held for moderation") post.comment ("Frist");
Admin
Where's the WTF? New person comes in, introduces modern coding practices, starts untangling spaghetti code.... He's not fired, there's no reversal of the new practices. IDGI, this is just a CodeSOD with a story hung on it.
Admin
TRWTF is two missing semicolons. FAILURE!
Admin
TRWTF is comparing a bool with false
Admin
Sorry, you're wrong :( volatile is used when dealing with hardware access (memory-mapped IO) and in some multithreading situations. Please check the available online documentation.
Admin
No, that's a perfectly cromulent comparison. A bool is even true or false.
Admin
No, that's a perfectly cromulent comparison. A bool is either true or false.
Admin
"TRWTF is thinking volatile has anything to do with multithreading."
Clearly it does. If your compiler is stupid and wrongly assumes that because a variable is not changed in one thread it isn't changed at all, then "volatile" cures it of that stupidity.
Admin
Confuzzled: What do you mean? Volatile means that the access isn't cached. The only time you ever use it is with multithreading.
Admin
"TRWTF is thinking volatile has anything to do with multithreading."
Er, the first line of https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile says "The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time."
Admin
Right. I think Confuzzled was guessing how volatile works in C# based on how it works in C and/or in C++, where it has different semantics and should not be used for multithreading. Guessing how a language works is not a good idea.
Admin
Well, there's some fun to be had by estimating how long it would take you to figure out the problem by staring at the code. (I'm not the best at this, as many C# reviews have made clear, but it took me about 30 seconds. And I wouldn't have used volatile, I'd have used a more appropriate locking/semaphore mechanism, but that's very small beer.)
TRWTF is, as so often, the submitter. You can follow all the "best practises" in the world, but you kind of need to keep your brain switched on when you do that. In this case the gain from best practises is to automate the build away from a local folder, and the loss is that, for no obvious reason at all, the automated build actually changes behavior by moving from a debug build to a release build.
Which might have an incremental advantage. Which you could test on the brand spanking new test machine mentioned in the article. Which evidently was not done. (Lacking other details, there might be problems with accessing the web services, although frankly you could still mock these out to some extent.) Which means that you essentially fail at the first hurdle of an automated deployment, which is to make sure that it actually bloody works.
Oh, who am I kidding? The actual real WTF is the use of web services in the first place. They have their role, but not as a giant unknowable abstraction slapped into place, as here, in place of a rational IPC. Web services in 2018 seem to be about as well-thought-out as Corba interfaces in the 2000s. And equally as brittle.
Admin
I've always used volatile to indicate memory mapped hardware peripheral registers in embedded systems.
Admin
C-language
volatile
has, according to the C standard, nothing to do with multithreading.Microsoft has a habit, in its compilers, of extending its meaning to include "multithread-proof", since at least the Visual C++ 6 days. It's natural that they would make this an official language feature when designing C#.
Admin
Sam replaced the function with inceptPassword, which encodes it twice
Admin
Oh, darn
Admin
TRWTF is "the very first thing he did was refactor the code to actually properly handle multiple threads".
Since the code was using an asynchronous method, but behaving synchronously to the caller, the first thing he should have done is simplify the code but make it work properly...
Admin
ITwerk it, yeah yeah, ITwerk it...
Admin
And that's TRWTF: "we even have a test machine… but we don't actually test our releases on it".
Admin
volatile does have a lot to do with multithreading, just typically not in a way people assume.
volatile prevents compiler from caching value, therefore everytime you read from or write to this variable it will happen without any caching, as in if you use variable 5 times then it'll be read from RAM 5 times, but without volatile it will be read only once. But volatile doesn't mean reads and writes cannot be rearranged so it's still not suitable for synchronization.