Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Threads?

What are the rules regarding spawning new threads within other running threads? I have a C# app that handles two basic threads in the background. I recently introduced some heavy duty IO stuff, and I was thinking of setting them off inside threads. Are threads nested within themselves cool?

like image 468
Olaseni Avatar asked Mar 25 '10 16:03

Olaseni


1 Answers

Threads aren't modelled as a hierarchy for the majority of their processing; the concept of "nesting" simply doesn't exist.

A thread executes in parallel to all other threads, regardless of which thread created it. The only things which matter in the creation of a thread is whether it is a background thread or a foreground thread and the priority of the thread:

  • Priority determines how many slices of time the thread is given when competing with other threads for resources. Higher priority means more slices.

  • Foreground threads keep a process alive until their work is completed. For background threads, when all foreground threads complete execution in a process, the process ends and the background threads are terminated, regardless of their work completed.

like image 124
Paul Turner Avatar answered Sep 26 '22 14:09

Paul Turner