Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am developing an application where application suppose to process the data of records (ranges from 1 - 500000). For each block i am creating threads,

If i am creating /destructing threads for at least 11k times, then .... is it the overhead ??


Thanks in advance.
-Prafulla



UPDATE :

I tried with creating thread at once. But it is adversaly affecting the performance. It is taking more time than creating threads at each time.

Is ther any thread specific memory related issue ???

NEED HELP
Posted
Updated 22-Jun-11 21:16pm
v2

Probably yes. You should arrange a little test to verify execution times. You may also have a look at Thread Pool Pattern[^].
 
Share this answer
 
Comments
Albert Holguin 21-Jun-11 9:19am    
my 5, thread creation overhead can be significant, if there's a case where you have to create multiple threads, you're better off creating them once and tasking them.
Joan M 21-Jun-11 9:25am    
5ed!
Guyverthree 22-Jun-11 4:21am    
Agree 5

I didn't know about design patterns but they are obviously very very useful.
Yes creating and destroying threads do have an overhead, perhaps the better option is to have one manager thread and then have worker thread to which you assign the work to from the manager thread.

hence you only create threads at the start of the program and have the wait on a message telling them which records to process.
Once done they send a message to the manager thread telling it they are done and want the next set of records to process.
 
Share this answer
 
Comments
KarstenK 21-Jun-11 9:59am    
He needs a global queue which is thread safe to distribute the queued jobs.
The count of threads should be balanced which count is optimal to perform. Timeouts, parallel tasks and dead locking are problems.
Guyverthree 21-Jun-11 10:06am    
Yes that is a fair point. The gobal queue is a must.

I was assuming that he must have thought about timeouts, parallel tasks and dead locking if he is creating 11K worth of threads already and wants the task to be completed successfully.
KarstenK 21-Jun-11 10:12am    
my tip is that 10 threads are enough, so 100 wont be much faster if he isnt populating a server farm.

Threading isnt the solution, but intelligent and clever code ;-)
Sergey Alexandrovich Kryukov 21-Jun-11 16:35pm    
Agree, my 5.
I added my 2 cents in my answer.
--SA
Very unreasonable overhead. You should re-think your design totally. There are could be different reasons for using threads. Do you need to more fully use your CPUs/cores (but then you hardly need more CPUs than cores) or thread represent logical entities of your application (such as in the famous problem of dining philosophers).

It is very likely that you can use one of a fixed small number of threads. You can also use the Thread Pool pattern, see http://en.wikipedia.org/wiki/Thread_pool_pattern[^].

—SA
 
Share this answer
 
Comments
Guyverthree 22-Jun-11 4:17am    
Agree 5 :)

I didn't know about design patterns but they are obviously very very useful.
Sergey Alexandrovich Kryukov 22-Jun-11 4:18am    
Thank you, Safar.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900