Free Code (Easy Multithreading)

Started by
14 comments, last by Zefrieg 19 years, 10 months ago
By the way, I looked a little closer and I don''t like this:

void WINAPI ThreadFunc(Thread* thread){
while(1) {
thread->Run();
}
}

This means that your thread objects will loop forever. This is not the standard way of doing things...usually you just call thread->Run() and if the thread needs to loop do it inside teh Run() method (i.e. the implementation). the way you have it, there is no way to free up the thread context since it runs forever. Furthermore, you will crash your system when you try to delete the thread (suddenly your thread pointer is invalid).

You need some way of determining what happens if someone tries to delete a thread that''s still running (this will cause stack corruptions up the wazzoo!). This means you need to provide a getStatus() function in Thread and in the destructor if block until the status is "complete" or whatever.

Bzzz...back to the drawing board with that class.

Regards,
Jeff

[ CodeDread ]
Advertisement
Also, you need to make your Thread destructor virtual!



[ CodeDread ]
The usual way of doing things it to make ThreadFunc a static member (thus avoiding the "this" problems) instead of a global function. But otherwise it''s ok.
-Mike
quote:Original post by Prozak
Yes, why dont we all just stop coding, and start using other people''s s**t?

argh, makes me mad when people instead of suporting you for doing the hard thing, slam you with "why didnt you use the ****"....

I''m only interested in end products, not how many wheels you reinvented along the way. He requested comments, and I provided quite a bit of constructive criticism.

Also:
Threads shouldn''t be in the Network namespace
There is no need to befriend the ThreadProc
The ThreadProc should have a catch-all exception handler to prevent exceptions from propagating to the OS
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
quote:Original post by antareus
quote:Original post by Prozak
Yes, why dont we all just stop coding, and start using other people''s s**t?

argh, makes me mad when people instead of suporting you for doing the hard thing, slam you with "why didnt you use the ****"....

I''m only interested in end products, not how many wheels you reinvented along the way. He requested comments, and I provided quite a bit of constructive criticism.


*whoooosh*

Thats the sound of my whole point going over your head, so i''ll make it clear enough for you:
- Wheels NEED to be re-invented from time to time, even if not for only educational purposes of the programmer himself.

This doesnt mean i dont understand that in a work environment there is no time to redo much of this stuff, or that in your attemps it wont be as fast/eficient/neat-looking as other open-sourced libraries out there coded and reviewed by dozens of programmers...

...but its something any decent programmer, worthy of that job position, should eventually come to do, much like using pointers, dinamic memory allocation, etc...

Salsa cooked it, your eyes eat it![Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD][My DevDiary]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"...if you had one shot, one oportunity, to seize everything you ever wanted for one moment, would you capture it? or just let it slip?" - Eminem
Unfortunately the thread title is rather deceptive; having a C++ wrapper class for a thread is fine - I''m not knocking you for doing it, but it won''t make multithreading easy.

Because of course, the hard part about multithreading is correctly locking data so that you don''t get race conditions and data corruption (and at a sufficiently fine-grained level that you actually get any benefit from threading, and don''t spend all your time in synch. code)

Mark

This topic is closed to new replies.

Advertisement