Thread
Thread
thread is Like a process, it means one execution unit.
A unit smaller than a process.
It’s a split in the process.
Process vs Thread
Prochess is the unit of resource(cpu, memory, I/O …) ownership.
Thread is the unit of dispatching.
Process switching is called context switching.
Thread exchange is also called context switching.
If there is a difference, switching between threads occurs very quickly.
picture [1] Threads in Process
Resource sharing between processes is not possible.
However, it is possible to share resources between threads within the same process.
IPC should be used for interaction between processes.
multi threading
The ability of an OS to support multiple, concurrent paths of execution with in a single process.
concurrency or parallel must be ensured.
As I posted in Overview, the two are different.
concurrency is that Through time sharing and context switching,
It runs as if it’s working at the same time.
It is not physically executed, but it can be said to be executed because it has not been terminated.
parallel is real working at the same time with multi core.
PCB : process control block
TCB : thread control block
picture [2] multi thread model
The PCB contains the TCB of each thread.
Eanch thread has a state (running, ready, etc …)
save context when not running.
As mentioned above, they can access to the memory and resorces of its process.
This is types of multithread model
picture [3] types of multithread
1 Process & 1 thread is typically ‘MS-DOS’.
The concept and term thread did not exist because all actions were performed by the process.
1 process & n thread is typically ‘JVM’.
+-----------+
| JVM |
+-----------+
| windows |
+-----------+
| H/W |
+-----------+
Java is because a virtual machine runs on Windows and acts on it.
Classic OS are implemented in a 1 process & 1 thread structure in a multi-process.
With the development of threads and multi-threads,
it has the current form(Windows, Linux, etc …) of multiple processes in the form of multi-threads of one process.
benefits of thread
thread has more benefits than process.
- Take less time to create than process.
- Take less time to terminate a thread than process.
- Take less time to switching between threads than processes.
- Take less time to communicate between threads than processes.
thread characteristics
This is thread characteristics.
- foreground and background work(job).
- asyncronous(non blocking) processing.
- speed execution.
- modular program structure.
So In a OS that supports thread, scheduling and dispatching is done on a thread basis.
Of course, When a process is suspended, all threads under it are suspended,
and when the process is terminated, all threads under it are terminated.
RPC
Remote(server) Procedure(function) Call
picture [4] Remote Procedure Call
It is to retrieve the necessary resources from the server.
Thread syncronize
Synchronization is when the other starts at the end of one,
and when the other ends, the other starts again.
That is, every time a thread is passed, it is cut off, which is called blocking.
Synchronization proceeds on with blocking.
Asynchronization proceeds on its own without blocking.
picture [5] Sync vs Async
Since threads in a process are connected, resource needs should not conflict.
ULT KLT
ULT :
User Level Thread. (user mode)
multi-core is compatible. (parallel)
but, It should be implemented by the programmer.
null-fork/signal wait is very fast.
picture [6] ULT
kernel isn’t aware of ULT.
In the right case, if the process is blocked while the thread is in progress,
all threads will die. Mismatch has occurred.
There were many errors at the beginning of the thread.
KLT :
Kernel Level Thread. (kernel mode)
multi-core is compatible. (parallel)
Even if there is one process, multiple threads can be executed per core.
null-fork/signal wait is very slow
Leave a comment