Thread in Operating System
Threads and Multi-Threading
What is a Thread: Threads are like smaller parts of a process that can run separately but share the same resources, like memory and files. Each thread has its own program counter, registers, and stack.
Multi-Threading:
Multi-threading is when a process is split into multiple threads to do different tasks at the same time. For example, in a browser, each tab could be a thread. This helps make programs faster and more responsive.
Benefits:
- Responsiveness: A thread can finish its task and give results quickly without waiting for the whole process to finish.
- Faster Switch: Switching between threads is quicker than switching between whole processes.
- Better Use of CPUs: Multiple threads can run on multiple processors, speeding up tasks.
- Resource Sharing: Threads in the same process can share resources like memory and files, making communication easier between them.
- Higher System Throughput: More jobs can be done in less time if a process is divided into threads, improving overall performance.
Types of threading in an operating system
There are two types of threads we can find.
User-Level Threads:
- These threads are created without using system calls, so the kernel doesn’t manage them. Users can easily create and manage these threads. However, if a process with these threads needs help, the kernel will step in.
- Advantages:
- Easier to create and manage.
- Faster switching between threads.
- More efficient because they are simple.
- Disadvantages:
- Poor coordination with the kernel.
- A problem in one thread can block the entire process.
Kernel-Level Threads:
- These threads are recognized and managed by the operating system’s kernel. The kernel keeps track of all these threads and helps manage them, although switching between them takes more time.
- Advantages:
- The kernel always knows the state of all threads.
- Handles processes that block often.
- Can give more processing time to threads that need it.
- Disadvantages:
- Slower than user-level threads.
- More complex to implement.
Difference Between Process and Thread
References:
hhttps://www.shiksha.com/online-courses/articles/threads-and-multi-threading-operating-system/ttps://www.geeksforgeeks.org/thread-in-operating-system/?ref=gcse_ind
https://www.google.com/url?sa=i&url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F45187940%2Fpython-multithreading-model&psig=AOvVaw0zyORlMi3eDAjHkcSHpylH&ust=1724147716012000&source=images&cd=vfe&opi=89978449&ved=0CBcQjhxqFwoTCKCx-vPkgIgDFQAAAAAdAAAAABAQ
i like this one, nice and short.
ReplyDeletetoo short for my liking.
DeleteYou’re on the right track, but I think you could push this further
Delete