Click here to Skip to main content
15,888,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Is it a good practice to start a thread (T2) inside another thread (T1) (other than main thread M1)?

What practical issues i will face if we go for this kind of design?

Regards,
Posted

I don't see direct issues related with this choice. However you have at least two places where threads start (and possibly stop). This additional complexity, in my opinion, should be justified by an overall improvement of your design.
My two cents.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-May-12 19:29pm    
There are no any issues related to this. My 5.
Wait a minute... why two different places (start/stop)? Yes, it could be a bad practice or just an unwanted complication, but I see no difference in in what thread this is done.
--SA
Sergey Alexandrovich Kryukov 7-May-12 19:36pm    
I decided to add my own answer, which might make things clear -- please see.
--SA
There is practically no difference between main thread and other threads. Strictly speaking, there is not such thread as "main", this is merely some initial thread, the one where the entry point is executed. This kind of design cannot add any hassles or problems. There is only one thing: each thread should serve some purpose which should justify its use and spending resources for it existence. Of course, if a sheer purpose of a thread is to create and/or start some other thread, this hardly could be a good design, but if this thread carries some distinct functionality, why not?

—SA
 
Share this answer
 
Comments
CPallini 8-May-12 8:15am    
Cannot understand why someone downvoted this. Have my 5.
Sergey Alexandrovich Kryukov 8-May-12 10:56am    
Oh, it was a series of votes of 1 on several answers in a row. Looks like I have a secret admirer who does no care what I write anymore... :-)\
Thank you for your vote.
--SA
You can start thread any time you need them, the trick and problem is resource contention.

If you can use .net 4 try Tasks instead of threads.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-May-12 19:31pm    
I voted 4. This is not about time of creation; this is about a thread creating a thread; the trick and resource contention is also irrelevant.
Tasks? It depends. They are based on threads anyway and not always applicable. Threads are more universal.
--SA
Sergey Alexandrovich Kryukov 7-May-12 19:36pm    
I just decided to add my own answer, which might make things clear -- please see.
--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