Click to See Complete Forum and Search --> : create multiple thread under one thread


dragondad
September 1st, 2005, 06:21 PM
I have a project to convert the existing multiple process model to multiple thread model. Beside the benefit I can get from the multiple thread model (NO more IPC, yes), one real concern is that I have to create multiple thread under one of the thread.
The story is like this, the main program should create several threads (to replace the processes), and one of the thread should create its own multiple threads (to mapping the old design). The question are:
1. is this design work?
2. if this design work, what is the possible problem for multiple level thread. can the subthread of the thread directly communicate with the main program?

Please let me know if you have similar experience before, I like to know.
Thanks.

wildfrog
September 1st, 2005, 06:50 PM
1. is this design work?
IMO, this is OK.

2. if this design work, what is the possible problem for multiple level thread. can the subthread of the thread directly communicate with the main program?
There is no such thing as "multilevel" threads, they are all directly "beneath" the process. As the "main thread". All threads may communicate with eachother using shared resources (variables, lists, collections, memory regions etc.) but you'll have synchronize access between them. One thread shouldn't modify a variable while another is trying to read it (race conditions).
So, you'll have to look into thread synchronization.

And, you'll have to avoid such thing a deadlocks. A deadlock is what you get if one thread holds a lock a variable A, and waits for variable B, while another thread holds a lock on variable B, and waits for variable A... you see? Both thread would be waiting for eachother... until end of time.

So, anything is possible, but you'll have to be cautious.

- petter