Designing Thread Safe Programs

Everything else that doesn't fall into one of the other PB categories.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Designing Thread Safe Programs

Post by Dreglor »

I am in the process of writing some network based software for my own use and I thought the best way of handling it would be through a thread pool like system.
I did write something like that a while ago here:
http://www.purebasic.fr/english/viewtopic.php?t=24417
but, I am unsure how well it will withstand considering I am throwing a lot of memory buffers and pointers I was wondering what is the do's and don'ts of programming asynchronously efficiently with threads and does it matter that the end-user has a muilt-core system or not?
~Dreglor
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Your code looks to have a good design for mutexes already so you should be okay. I don't think multi cores should give you any new trouble, just increase the likelyhood of threads bumping into eachother or locking if mutexes are not used where they are supposed to be.

Doing these sorts of threaded net apps in the past the hardest part has been the method for queueing so that if you have 1000 tasks (like reading reg keys from every system on the network) and want to do it with 20 threads to come up with a clean queue that can be mutexed without locking up. I wonder if a linked list would make a good queue ....
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply