Comment On Flossin' My Threads

Everyone knows that, when it comes down to it, it's all about the threads. Now, most coders ... they only use a single thread. Heck, some probably don't even realize that they're even codin' on a thread. All they know is that they write code, the computer runs it, and that's that. But the true, hard-core, and if I may say, gangsta' coders ... *they* go multi-threaded. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Flossin' My Threads

2006-08-10 14:57 • by jo42
:%s/Threads/Threadz/g

Re: Flossin' My Threads

2006-08-10 14:57 • by mastmaker

fist?


I know what you mean. I have met those gangsta (like Jerry) coders myself.


 


Captcha: quality!

Re: Flossin' My Threads

2006-08-10 14:59 • by 'tini
85514 in reply to 85513
Just so I know to avoid it, which site is "known best for its presentation of astonishingly low-quality,
unedited articles and code samples"?

Re: Flossin' My Threads

2006-08-10 15:00 • by Lunaris
s/C\+\+ Experience/Debauchery/g

Re: Flossin' My Threads

2006-08-10 15:02 • by evan
85516 in reply to 85514
I'm guessing the low-quality code snippet site in question is expert-exchange.com, what do I win?

Re: Flossin' My Threads

2006-08-10 15:02 • by Raider
85517 in reply to 85513
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.

Re: Flossin' My Threads

2006-08-10 15:04 • by Raider
85518 in reply to 85514

Anonymous:
Just so I know to avoid it, which site is "known best for its presentation of astonishingly low-quality, unedited articles and code samples"?


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 :)

Re: Flossin' My Threads

2006-08-10 15:04 • by R.Flowers
85519 in reply to 85514
Anonymous:
Just so I know to avoid it, which site is "known best for its presentation of astonishingly low-quality,
unedited articles and code samples"?


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?


Re: Flossin' My Threads

2006-08-10 15:09 • by WeatherGod
"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".

Re: Flossin' My Threads

2006-08-10 15:09 • by WTF ..
85523 in reply to 85519
R.Flowers:
Anonymous:
Just so I know to avoid
it, which site is "known best for its presentation of astonishingly
low-quality,
unedited articles and code samples"?


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?






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.

Re: Flossin' My Threads

2006-08-10 15:12 • by Steve

Don't come down on Brian R too hard.  His daughter Paula won't think he's brilliant.


 

Re: Flossin' My Threads

2006-08-10 15:13 • by Bg Porter
  "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...

Re: Flossin' My Threads

2006-08-10 15:16 • by drdamour
Alex Papadimoulis:


public int ProcessIncomingMessage
  (int messageId, int messageType, char* message)
{
  //spawn a new listener so we can process this
  int h = CreateThread(
    NULL, 0, ListenForMessage,
    (void *)this, 0, NULL);

  //now process the message
  int result = -1;
  switch (messageType)
  {
    case MSGTYP_M001:
      result = ProcessCvlMessage(messageId, message);
      break;
    case MSGTYP_M002:
      result = ProcessAplMessage(messateId, message);
      break;
    case MSGTYP_M003:
      if (this->routingLevel == 1)
        result = ProcessLcxMessage(messateId, message);
      else
        result = ReRouteMessage(messateId, MSGTYP_M008, message);
      break;


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...

Re: Flossin' My Threads

2006-08-10 15:16 • by GoatCheez
Alex Papadimoulis:
"Huh," Jerry responded, "I’ve only used Windows and, besides, isn't UNIX based on Windows."


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 ;-)

Re: Flossin' My Threads

2006-08-10 15:18 • by cout
85529 in reply to 85525
I think you mean "brillant".

Re: Flossin' My Threads

2006-08-10 15:19 • by Raider
85530 in reply to 85525
Anonymous:

Don't come down on Brian R too hard.  His daughter Paula won't think he's brilliant.



You mean on "Jerry"

Shenanigans

2006-08-10 15:19 • by S$

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]

Re: Flossin' My Threads

2006-08-10 15:19 • by Alex Papadimoulis
85532 in reply to 85518
Raider:

Anonymous:
Just so I know to avoid it, which site is "known best for its presentation of astonishingly low-quality, unedited articles and code samples"?


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 :)



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"

Re: Flossin' My Threads

2006-08-10 15:21 • by Raider
85534 in reply to 85528

GoatCheez:
Alex Papadimoulis:
"Huh," Jerry responded, "I’ve only used Windows and, besides, isn't UNIX based on Windows."


Yup, just like how apples are based on frogs.... WTF lol...
That line literally made my job drop.


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. 

Re: Flossin' My Threads

2006-08-10 15:21 • by enigmatic
85535 in reply to 85528
GoatCheez:

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 ;-)


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?

Re: Flossin' My Threads

2006-08-10 15:22 • by Anonymous
85536 in reply to 85527
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!

Re: Shenanigans

2006-08-10 15:22 • by Raider
85537 in reply to 85531

Anonymous:
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.


That code snippet was just something Alex used to illustrate the scanario, not something the guy actually wrote.

Re: Flossin' My Threads

2006-08-10 15:24 • by Raider
85538 in reply to 85536

Anonymous:
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!


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

Re: Flossin' My Threads

2006-08-10 15:25 • by channer
85540 in reply to 85532
Alex Papadimoulis:
Raider:

Anonymous:
Just so I know to avoid it, which site is "known best for its presentation of astonishingly low-quality, unedited articles and code samples"?


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 :)




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"



you have a point with the unedited articles - the site in general is a pretty good c# resource though.

Re: Flossin' My Threads

2006-08-10 15:29 • by Jboss
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...

Captcha: knowhutimean

Re: Flossin' My Threads

2006-08-10 15:31 • by Raider
85542 in reply to 85541

Anonymous:
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...

Captcha: knowhutimean


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 ...

Re: Flossin' My Threads

2006-08-10 15:34 • by WeatherGod
85543 in reply to 85542
Raider:

Anonymous:
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...

Captcha: knowhutimean


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 ...





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...

Re: Flossin' My Threads

2006-08-10 15:35 • by drdamour
85544 in reply to 85542
Raider:

Anonymous:
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...

Captcha: knowhutimean


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 ...



 


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.

Re: Flossin' My Threads

2006-08-10 15:37 • by kbiel
85545 in reply to 85536
Anonymous:
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!


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.

Re: Flossin' My Threads

2006-08-10 15:38 • by Raider
85546 in reply to 85544
drdamour:
Raider:

Anonymous:
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...

Captcha: knowhutimean


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 ...



 


so you're saying that when a message was received, that thread didn't die once the message was routed appropriately?



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.

Re: Flossin' My Threads

2006-08-10 15:40 • by Madcat
85547 in reply to 85527
drdamour:
Alex Papadimoulis:


public int ProcessIncomingMessage
  (int messageId, int messageType, char* message)
{
  //spawn a new listener so we can process this
  int h = CreateThread(
    NULL, 0, ListenForMessage,
    (void *)this, 0, NULL);

  //now process the message
  int result = -1;
  switch (messageType)
  {
    case MSGTYP_M001:
      result = ProcessCvlMessage(messageId, message);
      break;
    case MSGTYP_M002:
      result = ProcessAplMessage(messateId, message);
      break;
    case MSGTYP_M003:
      if (this->routingLevel == 1)
        result = ProcessLcxMessage(messateId, message);
      else
        result = ReRouteMessage(messateId, MSGTYP_M008, message);
      break;


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...



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.

Re: Flossin' My Threads

2006-08-10 15:40 • by Raider
85548 in reply to 85545

Anonymous:
Anonymous:
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!


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.


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.

Re: Flossin' My Threads

2006-08-10 15:43 • by drdamour
Alex Papadimoulis:

 When he reviewed the code, Brian noticed was that there were a lot of copy/pasted functions, many in completely different coding styles. On a whim, Brian did a quick google search on one of the functions. And then another. And then another. After only a few minutes of searching, Brian found code from nine different articles, all posted on a certain website known best for its presentation of astonishingly low-quality, unedited articles and code samples.


Alex Papadimoulis:
public int ProcessIncomingMessage

(int messageId, int messageType, char* message)
{
//spawn a new listener so we can process this
int h = CreateThread(
NULL, 0, ListenForMessage,
(void *)this, 0, NULL);

//now process the message
int result = -1;
switch (messageType)
{
case MSGTYP_M001:
result = ProcessCvlMessage(messageId, message);
break;
case MSGTYP_M002:
result = ProcessAplMessage(messageId, message);
break;
case MSGTYP_M003:
if (this->routingLevel == 1)
result = ProcessLcxMessage(messageId, message);
else
result = ReRouteMessage(messageId, MSGTYP_M008, message);
break;

--- snip ---

After they let Jerry go, Brian spent two months rewriting the entire subsystem from scratch, taking full advantage of the C++ Standard Library instead of MFC. And this time, the SME compiled on both Windows and UNIX, didn't mix up messages, and was monumentally faster than its predecessor. Brian, you are a true, hard-core gangsta' coder.



is it coincidence that googleing "C++ CreateThread" first result was


http://www.codeproject.com/threads/thread_win32.asp


with this gem of an example


CreateThread ((NULL, 0, (unsigned long (__stdcall *)(void *))this->runProcess,
    (void *)this, 0, NULL);

Re: Flossin' My Threads

2006-08-10 15:44 • by danielpitts
85550 in reply to 85527
drdamour:
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...


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 *?

Re: Flossin' My Threads

2006-08-10 15:45 • by snoofle
85551 in reply to 85548

<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>

Re: Flossin' My Threads

2006-08-10 15:46 • by HeroreV
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.

Re: Flossin' My Threads

2006-08-10 15:47 • by Grimoire
85553 in reply to 85544
drdamour:
Raider:

Anonymous:
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...

Captcha: knowhutimean


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 ...




 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.


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.

Re: Flossin' My Threads

2006-08-10 15:48 • by drdamour
85554 in reply to 85552

HeroreV:
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.


 


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.

Re: Flossin' My Threads

2006-08-10 15:48 • by WHO WANTS TO KNOW?

MY GOD!!!!!!  How do such STUPID people find work!


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****


 

Re: Flossin' My Threads

2006-08-10 15:49 • by snoofle
85556 in reply to 85552

HeroreV:
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.


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 ***

Re: Flossin' My Threads

2006-08-10 15:51 • by drdamour
85557 in reply to 85553
Grimoire:
drdamour:
Raider:

Anonymous:
I realy dont see a WTF here. And the snippet seams just fine (other than what it does ofc)...

Captcha: knowhutimean


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 ...



 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.



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.


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.


 

Re: Flossin' My Threads

2006-08-10 15:53 • by Raider
85558 in reply to 85554
drdamour:

HeroreV:
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.


 


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.



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 ..

Re: Flossin' My Threads

2006-08-10 15:53 • by HitScan
85559 in reply to 85532
Alex Papadimoulis:
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"


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.

Re: Flossin' My Threads

2006-08-10 15:53 • by channer
85560 in reply to 85542
Raider:


snip..

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 ...



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.

Re: Flossin' My Threads

2006-08-10 15:54 • by Benanov
85561 in reply to 85522
WeatherGod:
"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".


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.)

Re: Flossin' My Threads

2006-08-10 15:55 • by Anonymous
85563 in reply to 85545
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.

Re: Flossin' My Threads

2006-08-10 15:56 • by drdamour
85564 in reply to 85558
Raider:
drdamour:

HeroreV:
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.


 


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.



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 ..



 


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


 

Re: Flossin' My Threads

2006-08-10 15:56 • by Raider
85565 in reply to 85557

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.

Re: Flossin' My Threads

2006-08-10 15:59 • by Grimoire
85567 in reply to 85549
drdamour:

is it coincidence that googleing "C++ CreateThread" first result was


http://www.codeproject.com/threads/thread_win32.asp


with this gem of an example


CreateThread ((NULL, 0, (unsigned long (__stdcall *)(void *))this->runProcess,
    (void *)this, 0, NULL);


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.

Re: Flossin' My Threads

2006-08-10 16:00 • by drdamour
85568 in reply to 85565
so why was it processing messages wrong?
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment