Threading Newbie

barski

Junior Contributor
Joined
Apr 7, 2002
Messages
240
Location
Tennessee
I've done very little with threading and i mean very little. From my initial reading i can see the advantage to freeing up the app to do other things while a particularly long process is running.

However, in a single cpu environment there wouldn't be any kind of performance gain with the implementation of threading correct???

for example if i have

job1
job2
job3

the amount of time it would take for jobs 1-3 to complete would be the same if i ran them sequentially or spun them off into three different threads???

if it matters, can't imagine that it would, all jobs do bascially the same thing getdata(), changedata(), senddata()
 
On a single CPU the overheads of thread management might even cause a (very very) slight performance drop - probably not large enough to worry about though.

However it's not just the overall time that you need to consider but also the user's perception.

If job1 was to take 5 minutes and effectively hung the UI while it was working (no repaints, (not responding) in the titlebar etc.) then it gives a poor impression. Running the activity in a 2nd thread would at least keep the main UI responsive and give a better overall impression.
 
Another place multi-threading might help: suppose you were to download a file and perform some other additional operation. A file download isn't particularly CPU intensive, which means that you can use two threads to use all that extra CPU power and do both at once instead of waiting for the download to finish.

Also, in the event that a user has a pentium with hyperthreading, theoretically an operation may perform faster if done using multiple threads, but I certainly wouldn't base a program around that.
 
thanks for the input. i'm definetly going to use threading because there are a couple of places where i have to free up the app to do other things.

so i guess 100 one second jobs are going to take 100 seconds.
 
Back
Top