Thread Query in vc++
-
I have developed a VC++ program based on communication(online program). In the application,i have used two threads for computation. The working time of two threads is very less. my query is ... 1)If the thread is opened and closed each time for computation, will the program memory grow??? or what is the drawback?? OR Is it advisable to run the thread with sleep mode without closing the thread?? Help me...... Empty mind is Devils-Workshop
-
I have developed a VC++ program based on communication(online program). In the application,i have used two threads for computation. The working time of two threads is very less. my query is ... 1)If the thread is opened and closed each time for computation, will the program memory grow??? or what is the drawback?? OR Is it advisable to run the thread with sleep mode without closing the thread?? Help me...... Empty mind is Devils-Workshop
madhu_v wrote:
1)If the thread is opened and closed each time for computation, will the program memory grow??? or what is the drawback?? OR
every time when thread is created it will take some memory.. i.e. overhead.., if computation take less time , then why creating thread , why not include in main program!
madhu_v wrote:
s it advisable to run the thread with sleep mode without closing the thread??
yes and no! wholly depend upon the software design.. you can use event or waitforsingleobject to make thread wait
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
I have developed a VC++ program based on communication(online program). In the application,i have used two threads for computation. The working time of two threads is very less. my query is ... 1)If the thread is opened and closed each time for computation, will the program memory grow??? or what is the drawback?? OR Is it advisable to run the thread with sleep mode without closing the thread?? Help me...... Empty mind is Devils-Workshop
Thread creation is a relatively expensive operation, both in space and time. If you spawn a thread and let it run to completion nothing is permanently lost however - assuming of course that your code doesn't contain any memory (or other resource) leaks. If you’ve got lots of small tasks you want to run in another thread and you spawn a thread for each task you could easily find that the thread creation and destruction time dominates and causes performance problems. One solution to this is to use a thread pool. See the
QueueUserWorkItem
API.Steve