Oct 05 2009 - 10:14 AM
OS Class - Oct 05, 2009
- User threads
- Kernel Threads
Linux - task_struct has mm_struct (&mm) points to another task_struct (mm_struct) points to the same then its a thread and another mm_struct it's process.
kernel threads - share address space.
there is a thread count associated with the processes :-
fork() - creates a process not associated with a process.
When you do getpid() - returns processid
Different os has different concepts for threads:
fork means create a copy of task_struct and what it means the process or thread_struct which forks gets copied.
gettid - gives thread id.
linux has a concept of task group leader so the id of the task group leader is returned as pid for the process
task_pid refers to the tasks pid.
Lightweight process is basically kernel thread.
main issue with the use of thread is synchronization
t1 and t2 have both the threads int x;
Thread gets created in Linux using Clone (sys_clone)
one of the flags which is more interesting CLONE_VM (which shares memory between processes or threads).
x++ corresponds to LD x, ADD X, 1 , WR X