Wednesday, October 2, 2013

Threads vs Process on Linux

See the following links:
http://www.samba.org/~tridge/talks/threads.pdf
http://www.mulix.org/lectures/kernel_workshop_mar_2004/things.pdf
http://en.wikipedia.org/wiki/Thread_%28computing%29

Thread has its own stack, its own register set/context. User space threads or kernel space threads?
The context of a thread is the register set, including the stack pointer.
Context switch between threads includes saving registers, restore registers only, while MMU context(Page table) & TLB stays.

Process has its own virtual address space, and has at least one thread; all threads within it share the parent process's virtual address space.
The context of a process includes state, priority, signal info, process id, and a pointer to thread.
Context switch between processes needs a switch of virtual address space, including cache and TLB flushing, MMU context switching, and thread switching.

Both thread and process 's creation in user space went to the same system call(clone) in the kernel.
Linux implements 1:1 model.
Keep in mind, TLB and MMU context is per-CPU on Linux.

No comments:

Post a Comment