Can i open some threads from inside a thread?
I have a Windows service whit 2 different roles. When the service starts, I open 2 threads: one for each role. In each thread I need to open sub threads.
How many threads can I open for each core?
Can i open some threads from inside a thread?
I have a Windows service whit 2 different roles. When the service starts, I open 2 threads: one for each role. In each thread I need to open sub threads.
How many threads can I open for each core?
Sure you can instantiate other threads from a thread - as for how many this may prove useful : Optimal number of threads per core
It's worth keeping in mind that threads come with a cost of their own, and adding threads to increase performance only works to a point.
There is no hard limit... is as long as framework has sufficient resources and free handles etc. In past one of my app ran about 150 threads at peak.
Within spawn threads, we used to spawn more threads as needed which use to execute tasks we needed processing.
After a while we moved to using ThreadPool as its less resource intensive and there is a 1024 thread allocation on app start
Remember each thread when active gets scheduled by OS scheduler and do you want many hot threads. so when not doing anything, either put those threads to sleep or if using ThreadPool just exit current iteration to release the thread back to the pool
For .NET Framework its worth reading these
Threads and Threading
http://msdn.microsoft.com/en-us/library/6kac2kdh.aspx
Using Threads and Threading
http://msdn.microsoft.com/en-us/library/e1dx6b2h.aspx
Having said that be careful of what you create. You might need to worry about thread safety, locking, synchronization however you want to put it. Debugging the app also becomes a bit more difficult