Thread = basic unit of CPU utilization , Thread ID + PC(program counter) + register set + stack
in multi thread = code ,date ,file are shared but they have their own register and stack.
benefits
Responsiveness = muti thread operate simultaneously even if one thread takes long time or get blocked , user can still interact with other theads that is working fine.
Resource sharing = allows an application to have several different threads of activity within the same address space.
Economy = context-switch threads is much more eiffcient than context-switch process. since they are sharing resources.
Utilzation of mutiprocessor architectures = with mutiple CPU core and muti thread process wil run concurrently using mutiple core for each thread.
Types of Threads:
User Threads - Supproted above the kerenl and are managed without kernel support
Kernel Threads - Supported and managed directly by the operating system
User threads and Kernel threads Relationship
many to one model
- maps many user thread to one kerenl thread.
- able to manage thread in user space which is efficient.
- entire proces get block if a thread makes a blocking system call = kernel thread will be blocked therefore other threads will get block
- since only one thread can access the kernel at a time, mutiple threads are unable to run in parallel on mutiprocessors.
one to one model
- even if one thread makes blocking system call entire process won't get block.
- allows mutiple threads to run in parallel on muti processors.
- creating one user thread require one kerenl thread = costly
- having many kernel thread is heavy. also system will restrict the number of kernel thread that it can handle.
many to many model
- many user threads will map to equal or smaller number of kernel threads.
- developer can create many user thread and it will run parallel in muti processor system.
- even with blocking system call , the kernel can schedule another thread for execution.
Hyper-threading , Simultaneous Muti-threading (SMT)
many of muti-thread process are exisiting.
physical number of core process they are divided into mutiple logical processor
it enables the processor to execute 2 threads or sets of instructions , at the same time. since hyper-threading allows 2 streams to be executed in parallel , it's like having 2 seperate processors working together.
fork()
system call , to create a separate , duplicate process but process ID will be different.
5837 is the parent process ID and 5838 is the forked process ID.
exec()
system call , the program specified in the parameter to exec() will replace the entire process , including all threads.
it is like recursive call as soon as execv was called , it jumped to ex2 program and execute and then did not came back to ex1.
notice Process ID are same. which means Process 's contents are replaced it is not created.
'Operating System > O.S(Neso Academy, HPC Lab. KOREATECH)' 카테고리의 다른 글
11)Preemptive Scheduling , Scheduling Criteria , FCFS(First-Come, First-Served) Scheduling (0) | 2021.05.11 |
---|---|
10)Threading issue (fork , cancellation) , CPU and I/O burst cycles (0) | 2021.05.10 |
8) Sockets , Remote Procedure Call(RPC) (0) | 2021.05.06 |
7)Shared Memory Systems , Message Passing Systems (0) | 2021.05.05 |
6) Process Creation , Termination ,InterProcess Communication (0) | 2021.05.04 |