[Ilugc] [OT] OS concepts -Threads

  • From: girish1729@xxxxxxxxx (Girish Venkatachalam)
  • Date: Sun Sep 24 14:44:39 2006

On Sun, Sep 24, 2006 at 03:33:09AM -0400, peevee wrote:

Hi friends,

This is not related to OSS or Linux,
but I want to be cleared some concept of Operating Systems in general.

What happens if a process exits, and there are still threads of that process
running?

Wonder why you marked it OT.

If a process exits, the threads also die. Remember a process is defined by 
context and the most important aspect is its address space. A context has 
several components like contents of Ax,Bx,Cx,Dx regs if it is x86, signal mask, 
state(running,sleeping etc.) , stack etc...

Now, each thread has a lightweight context associated with it, the most 
important thing here being its stack. 

So when a process is divided into threads , basically the global process 
context is split into diff threads. All of them map to the same address space.

If you try to access memory outside the bounds of the address space allocated 
to the process, a hardware trap is generated by the MMU.

Now, the moment a process dies, its address space is removed from the MMU and 
all page tables cleared of its existence.

So there is no room for any thread to run. Essentially I mean that thread's 
context has to be stored somewhere, if it does not have an address space 
mapping where will it go?

Remember I am only talking of user space threading. Kernel threading is a 
different ballgame.

This is a deep theoretical topic and my memory certainly is rusty. Maybe u 
shudnt trust my words much. :-)

Best,
Girish

PS : I think some student will do a much better job than me in elucidating this

Other related posts: