- 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
:%s/Threads/Threadz/g
Admin
fist?
I know what you mean. I have met those gangsta (like Jerry) coders myself.
Captcha: quality!
Admin
Just so I know to avoid it, which site is "known best for its presentation of astonishingly low-quality, unedited articles and code samples"?
Admin
s/C++ Experience/Debauchery/g
Admin
Alex, I like your edit better than when I originally submitted it to you :P ... And I don't mind people knowing its me, if they fire me, they fire me (See 'Job "Security" ... HA' in the Side Bar WTFs) .. Its Brian K, not Brian R :) ... Well done Alex.
Admin
I don't think I'm allowed to post on here what sites he found the code snippets on without getting Alex in trouble, but feel free to email the address attached to my profile here :)
Admin
I honestly thought this was a sly reference to TheDailyWTF.com. :) I mean, how awesome would it be if some clueless coder actually copied code (try saying that 5 times fast) from here, and it eventually showed up... back here?
Admin
"I’ve only used Windows and, besides, isn't UNIX based on Windows."
You ain't truely a gansta if you never mixed it up with the *nix-es, word.
Meanwhile, a good song to play while reading this post is that rap in "Office Space".
Admin
umm... you mean we are not supposta use this code in our "Enterprise" apps?
...
umm .. I think maybe I might need some help then.
when in doubt?
Knock them out.
Admin
Don't come down on Brian R too hard. His daughter Paula won't think he's brilliant.
Admin
"you can't use MFC if you ever want to compile something outside of Windows"
-- for what it's worth, you actually can buy a porting layer from mainsoft (www.mainsoft.com) that makes moving MFC projects to *nix pretty easy, or so they say.
I only know them because I still have a frisbee they gave me at a trade show a few years back...
Admin
Maybe it's only my 24 years of experience with c++, but why is this such a bad codeblock? I mean other than the message <> messate typos and the evil switch statement...
Admin
Yup, just like how apples are based on frogs.... WTF lol...
That line literally made my job drop.
I should start putting on my Resume:
40 Years experience in programming C++ in a Windows environment.
60 Years experience in programming C++ in a *NIX environment.
30 Years experience in programming C# in Windows 2003.
Of course, once they realize that I'm not even 30..... lol ;-P
"Uhhhhhhh, my father was a programmer too!" lol ;-)
Admin
I think you mean "brillant".
Admin
You mean on "Jerry"
Admin
I call shenanigans here. Half way through the method, the variable name changes from messageId to messateId. As far as I can tell (although it's been a while since I worked in C++), the only way this would compile is if there was a global variable called messateId, which is, well, unlikely.
[Note from Alex: this was a typo on my part]
Admin
I don't like to pick on specific companies or sites. But I figure that this reply will be burried far enough in the comments that a clue should be ok. The website in question (and I should note that I get a LOT of submissions directly linking to this site) starts with the the letter "c" and ends with "odeproject.com"
Admin
Yeah, I got a HUGE laugh when he said that to me ... I really thought he was kidding at first, but he wasn't, at all ... He was absolutely serious ... He had never heard of the C++ Standard Library, he had never heard of anything that wasn't MFC/VC++ related.
Admin
It's all about the dog years.
FYI I've been coding .Net for over 35 years alone
Capcha - "shizzle" Snoop Dog is working here now?
Admin
You're kidding right? Every call to the method spawns a new Thread! It might eventually get destroyed (I insist on the might seeing as this IS theDailyWTF), but still creating threads is costly!
Admin
That code snippet was just something Alex used to illustrate the scanario, not something the guy actually wrote.
Admin
The only time a thread got destroyed is when the connection was lost, and these systems were all built with the intentions of running for years without every shutting down. We're talking hundreds of threads to potentially thousands at some of our largest customer bases, with NO semaphore usage whatsoever ... This code was nothing but race conditions ... But atleast he avoided deadlocks! ha
Admin
you have a point with the unedited articles - the site in general is a pretty good c# resource though.
Admin
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...
Captcha: knowhutimean
Admin
You don't see a WTF in spawning hundreds of threads ?? Or using code found on places like codeproject.com in production applications ... Code that is most likely untested, or barely test, more often than not, not made by reputable developers/development groups/etc ?? .... Wow ...
Admin
People who don't see a problem with spawning threads without destroying them would probably also have a tendency to leak memory all over the place. Be sure not to step on any of it...
Admin
so you're saying that when a message was received, that thread didn't die once the message was routed appropriately? I think the snipet could have been better, especially since the post implied that the snipet was responsible for incorrect message routing.
Admin
No it's quite normal to spawn threads to do the work. But every good gansta coder knows, the boss don't give up his seat to do the dirty work, he sends workers off to do it. If he's a smart boss, he might throw a pool party for his workers and dispatch them to their jobs from there instead of incurring the expensive of calling them up.
CAPTCHA: java. Perfect, I've been gansta coding the coffee for 20 years myself.
Admin
No, this is a misunderstanding ... The program acted as a daemon, used to accept connects from various instances of other applications, drivers, 3rd party software, etc, etc ... Each connection is treated as a single client. Each time a client connected, that particular thread turned itself into a client thread, and spawned off another listener thread ... This was the recursive process it underwent, for hundreds of connections, where each connection was expected to remain established for months if not years.
Admin
It kinda depends on what is handled in the other functions i guess, but this could be a place to create a lot of threads which are not cleaned up.
a thread for every message is a bit to much i think, if there are let's say 100 messages per second i guess the server could have a nice cpu load for only creating and closing threads.
Admin
Yeah, spawning worker threads can often be helpful ... If you spawn off a few ... Spawning hundreds of them, all meant to stay running at all times, is without a doubt one of the most idiotic things anyone could do ... Especially without using any form of data synchronization.
Admin
<FONT color=#000000>
Admin
Maybe its just me, but that doesn't look like C++, or Java, but some frankenstein of the two.
Hmm, how would a Java programmer handle a void *?
Admin
<offTopic>
I sometimes share my pc with a blind person, so the screen-reader software is enabled. It's not too bad with normal English text, but it usually trips all over itself on technical jargon. Throw in the misspellings and technical words in this blog, and it's hilarious to listen to. Go M$ !!!
</offTopic>
Admin
The real WTF is that there is so little support for threads today. Try using a popular library in a thread and you'll probably get errors. You either have to reimplement things yourself or use special thread-safe libraries. Even the modern super-cool Boost library contains lots of stuff that isn't thread-safe.
Admin
It is irrelevant whether or not the thread is correctly shutdown once the message was handled. The point is, a NEW thread was spawned every time a message was to be processed. How many messages per second is this service meant to handle? If you are spawning a new thread for every message, I can tell you it won't be many. This is what thread pools were invented for.
Imagine what happens when the system receives 100 messages in a second (the upper limit, based on the 10ms timer): the OS will practically thrash itself to death trying to build up and tear down threads that often. Nothing wrong with worker threads, but knowin' how to use 'em is kinda important yo.
Admin
dood, threads are hard. Especially now that there are dual cores mroe and more in production. Writing multithreaded apps that work with one processor (so only one thread can be executing at any one time) is one beast, writing them so 2 threads can excute simultaniously is a Godzilla monster.
Admin
<FONT size=4>MY GOD!!!!!! How do such STUPID people find work!</FONT>
Jerry seemed like a nice guy; he had "20 years of C++ experience," which, at the time, was older than C++ itself.
That is a common piece of garbage! I was once asked if I had 5 years or more of experience with VB5, and I told them what I had(LESS THAN 5 years), and said that if ***ANYONE*** said they had more, they were LYING! Even the developer couldn't claim more, as the beta had changed a bit, etc... Still, they seem to ALWAYS want 5 years +, even if the product came out yesterday!
, wasn't joking. Brian, still being a nice guy, explained that you can't use MFC if you ever want to compile something outside of Windows. "Huh," Jerry responded, "I’ve only used Windows and, besides, isn't UNIX based on Windows."
Actually, windows is a stupid imitation of X windows(which ran over UNIX) which came out a year BEFORE M/S Windows! M/S Windows ran over M/S dos(which came out about 4 years BEFORE M/S Windows) which was an imitation of CP/M (which came out over 5 years BEFORE M/S DOS and about 1 year BEFORE MICROSOFT!!!!!!). CP/M is obviously loosly based to some degree on UNIX which came out about 5 years before THAT!
MY GOD! The I.E.E.E. standard predates microsoft by about 4 years!!!!! NOT, WINDOWS, NOT DOS, but the ****ENTIRE COMPANY****
Admin
This is why G-d invented semaphores - so you can wrap the wtf's safely!
*** If it was easy and all code was well-written, you wouldn't have a job making it better ***
Admin
Excuse my ignorance, but what would be the correct pattern for handling incoming (assuuming socket level) messages then?
I'd think you have a listener thread, that spans workers for every message it has. so is the WTF there that the worker thread was spawning a listner?
And how much of that snipet is of Alex's design vs what really was happening.
Admin
Yeah tell me about it, we have dual, quad, and even 8 CPU systems here (Some cases single dual-core CPUs, dual- dual-core setups, etc), some on loan from Dell for testing to see if we want to buy them ... I'll tell you what though, making sure you do accurate data synchronizations is definately a lot easier on a multi-core/multi-cpu system since your code will crash more often if you did it wrong heh ..
Admin
I find that particularly amusing.
It also explains why I always leave that site with a more confused feeling than when I arrived, only to find a simpler, less over-engineered answer somewhere else.
Admin
I think articles on sites like codeproject are only good if you take them in context. The WTF is when *developers* use it as a copy paste resource without understanding what the hell the code is doing. That's how they end up here.
Admin
You mean...Scarface the Rapper?
I got my SQL script cocked
Ready to lay down queries non-stop until I see your data tables drop
And let your managers know who done it
'Cuz when it comes to this database s*** you programmers know who run it
(modified; from "No Tears." With apologies.)
Admin
A threadpool should be used and obviously the thread has to be cleaned up, however delegating the next listen to another thread (sometimes referred to as "Leader / Followers") is not unreasonable to use as it avoids a context switch.
Admin
that is true, whenever we have a threading issue, the instructions to reproduce usually have the following parts:
Do a lot of stuff, fast
Not always reproducable
Get lots of people doing the same thing
Stand on your head
Run some other program
Leave the system and come back to it
etc. etc.
I'd take lots of reproducable hard crashing code, over intermittent crashing code any day. especially for in production, not debug mode systemts
Admin
Ok, let me straighten everything out now ...
It did *NOT* spawn a new thread for every *message*, it spawned a new thread for every *connection* ... A connection could send millions of messages, or only a few messages, could be online for a day, or for a year ...
The problem is it created hundreds of threads, period ... It doesnt matter if they would be destroyed a second later, or a year later ... Anyone that writes an app that spawns one thread per connection, and leaves them running, anticipating hundreds, to thousands of connections, really needs to go back to the drawing board and learn about non-blocking sockets, or select(), or some other form of socket management.
I agree with, and have used worker threads when handling massive quantities of data (Note: We're talking millions upon millions of transactions going through this app daily), but to spawn that many is a sure fire way to make anyone with half a brain about C++ gag.
Admin
I stumbled across this one recently: http://www.codeproject.com/system/xservice.asp
Full of memory leaks, crashes, re-implementing existing stl functionality, ignoring errors, you name it, it has it. Allocate memory in your class, and not even having a destructor is about as fundamentally wrong as it gets.
Admin
so why was it processing messages wrong?
Admin
Well I see that you enjoy the rich text editor...
While MS-DOS was influenced by CP/M and CP/M was influcenced by UNIX, they are seperate systems with seperate aims.
MS Windows has absolutely no relation to the X Windowing System in any way. (And it's not called "X Windows" dammmit!).
And WTF does the IEEE have to do with anything?