Recents in Beach

Thread


Previous                                                          Next⏩



What is a Thread?
A thread is a path of execution within a process. A process can contain multiple threads.
Why Multithreading?
A thread is also known as lightweight process. The idea is to achieve parallelism by dividing a process into multiple threads. For example, in a browser, multiple tabs can be different threads. MS Word uses multiple threads: one thread to format the text, another thread to process inputs, etc. More advantages of multithreading are discussed below
Process vs Thread?
The primary difference is that threads within the same process run in a shared memory space, while processes run in separate memory spaces.
Threads are not independent of one another like processes are, and as a result threads share with other threads their code section, data section, and OS resources (like open files and signals). But, like process, a thread has its own program counter (PC), register set, and stack space.
                                               Single thread

Advantages of Thread over Process
1. Responsiveness: If the process is divided into multiple threads, if one thread completes its execution, then its output can be immediately returned.
2. Faster context switch: Context switch time between threads is lower compared to process context switch. Process context switching requires more overhead from the CPU.
3. Effective utilization of multiprocessor system: If we have multiple threads in a single process, then we can schedule multiple threads on multiple processor. This will make process execution faster.
4. Resource sharing: Resources like code, data, and files can be shared among all threads within a process.
Note: stack and registers can’t be shared among the threads. Each thread has its own stack and registers.
5. Communication: Communication between multiple threads is easier, as the threads shares common address space. while in process we have to follow some specific communication technique for communication between two process.
6. Enhanced throughput of the system: If a process is divided into multiple threads, and each thread function is considered as one job, then the number of jobs completed per unit of time is increased, thus increasing the throughput of the system.
Types of Threads
There are two types of threads.
                         
   User Level Thread
                             Kernel Level Thread

User - Level Threads

The user-level threads are implemented by  users and the kernel is 
not  aware of the existence of these threads. It handles them as 
if they were single-threaded processes. User-level threads are small and much
 faster than kernel level threads. They are represented by a program counter(PC), 
stack, registers and a small process control block. Also, there is no kernel  
involvement in synchronization for user-level threads.

Advantages of User-Level Threads

Some of the advantages of user-level threads are as follows −
User-level threads are easier and faster to create than kernel-level threads. 
They can also be more easily managed.
User-level threads can be run on any operating system.
There are no kernel mode privileges required for thread switching in user-level threads.

Disadvantages of User-Level Threads

Some of the disadvantages of user-level threads are as follows −
Multithreaded applications in user-level threads cannot use multiprocessing 
to their advantage.
The entire process is blocked if one user-level thread performs blocking 
operation.

Kernel-Level Threads

Kernel-level threads are handled by the operating system 
directly and the thread management is done by the kernel. 
The context information for the process as well as the process threads is all 
managed by the kernel. Becauseof this, kernel-level threads are slower 
than user-level threads.

Advantages of Kernel-Level Threads

Some of the advantages of kernel-level threads are as follows −
Multiple threads of the same process can be scheduled on different 
processors in kernel-level threads.
The kernel routines can also be multithreaded.
If a kernel-level thread is blocked, another thread of the same process
 can be scheduled by the kernel.

Disadvantages of Kernel-Level Threads

Some of the disadvantages of kernel-level threads are as follows −
A mode switch to kernel mode is required to transfer control from one
thread to another in a process.
Kernel-level threads are slower to create as well as manage as compared to
 user-level threads

Multi-Threading

It might be easy to confuse multitasking with multi-threading. Multitasking 
is a general term for doing many tasks at the same time. On the other hand, 
multi-threading is the ability of a process to execute multiple threads at the 
same time. Again, the MS Word example is appropriate in multi-threading 
scenarios. The process can check spelling, auto-save, and read files from the 
hard-drive, all while you are working on a document.
Consider the following diagram. The threads share the same code, files, and 
data. 




Previous  NEXT⏩

                        

  1. What is an Operating System ?
  2. Discuss the structure off OS ?
  3. Explain type of OS?
  4. Explain Function of OS?
  5. Explain OS Services ?
  6. What do mean by system call ?List different type ofsystem call available ?

  1. what is process ? and Characteristics ?
  2. What is different process state? explain the same in details?
  3. write short note on user level and kernal level threads?
  4. explain what is thread and its type ?
  5. explain scheduler ? (short term,medium term,and long term)
  6. state and explain scheduling criteria ?
  7. Explain scheduling algorithm ? [ FCFS,SJF,PRIORITY,ROUND ROBINE.]    

  1. What is process synchronization ? explain critical section problem and race condition ?
  2. what is Race Condition ?
  3. what is critical section problem?
  4. explain classical problem of synchronization?
  5. explain bounded - buffer problem?
  6. explain reader - writer problem ?
  7. explain Dining Philosophers Problem ?
  8. explain semaphores ? its type ?

  1.  What is deadlock ?
  2. What are the 4 condition to produce deadlock ?
  3. explain methods of handling deadlock ?
  4. explain in detail deadlock prevention ?
  5. write short note on deadlock avoidance ?
  6. explain deadlock detection ? 
  7. explain Banker algorithm with example ? 








Post a Comment

0 Comments