Technical Point.

The Best Platform of Diploma CSE Students.

Subscribe Us

Breaking

Sunday, August 2, 2020

INTERPROCESS COMMUNICATION AND SYNCHRONIZATION

THREADS

A threads is a single sequence stream within a process , because threads have some of the properties of process they are sometimes called lightweight process

A threads can be any several stares (Running , Blocked, Ready  , or Terminate )

Each threads has its own stack

A threads has or consists of a program counter (PC), a register set and a stack space

Threads are not independent of one other likes processes a result threads shares with other threads their code section , data section, OS resource also known as task , such as open files and signals.

Advantage of Threads.-

     1.    Improve Responsiveness:-  If the process is divided into multiple threads then if One threads is completed, then immediately output will be responded . this response will be faster as compare to response of process.
Eg- SBTE Site.

      2.    Faster context Switching :- The context switching time between the treads is very very less as compared to context switching time between the process because the threads will have less context compared to process .
Resource Sharing :-
The resource like code, data, and files will be shared among all the threads with in the process but every threads will have its own stack and register
     4 .    Effective Utilization of Multiprocessor System :- If the process is divided into multiple threads, then different threads of the process can be scheduled onto a different CPU so that the process execution will be faster .
  
     5.    Economical :- the implementation of threads does not requires any cast . There are various programming language API’S which support implementation of threads eg-JAVA’s API, Threads.

6. Communication :- Communication between multiple threads belonging to same process is easier as threads share common address space.
Types Of Threads :-
1.    Kernel  Level Threads/System Threads :- System threads are threads created by OS t serve or execute user. These threads need a small data structure and a stack for the execution . switching between threads does not requires to change memory access information so it if fast
            2. User Level Threads :- User level threads are threads created by user                                application. These threads need only a stack and a program counter for                            their execution . No need for OS resource switching among threads is fast.

Difference between User level threads and kernel level threads-
USER LEVEL THREADS:-
1. These are created by user or programmer
2. OS can not recognize the user level threads
3. If one user level threads performing block system call them entire process will be blocked
4.  Dependent threads
5. Designing user level threads is easy
6. Less context
7. No H/W Support required
USER LEVEL THREADS:-
1. These are created by OS
2. OS recognizes the kernel threads
3. If one kernel level threads performing blocking system call . then another threads will continue the execution.
4. independent threads.
5. Designing kernel level thread is complicated
6. More context
7. Scheduling of kernel level threads require H/W support 
Note:- Threads scheduling also known as GANG Scheduling
There are three common way of establishing relationship between user threads and kernel threads.

Multithreading models are three types :-

1.    MANY – TO- ONE MODEL
2.    ONE-TO-ONE MODEL
           3.   MANY-TO-MANY MODEL

MANY – TO- ONE MODEL:- The many to one model maps many user-level threads to one kernel threads . however the entire process will block if a threads makes a blocking system call  .also because only one threads can access the kernel at time. However user few system continue to use the model because of it inability to take advantage of multiple processing cores

ONE-TO-MANY MOEL:- There is one-to one relationship of user level threads to the kernel level threads. This model provides more concurrency than the many to one model. It also, another threads to run when a thread  makes a blocking system call
The one to one model maps each user threads to a kernel threads.

MANY-TO-MANY MOEL :- The many to many model multiplexes many user level threads to a smaller or equal number of kernel threads  .
The number of kernel threads may be specific to either a particular machine.
Allows many user level threads to be mapped to many kernel threads.

Difference between process and Threads

PROCESS:-
1.    A process is the heaviest unit of OS
2.    Process own resource allocated by the OS
3.    Communication between independent process need to the help of OS
4.    Multiple process without using threads use more resource
Threads :-
1.    A threads is the lightest unit of OS. Existing within the process
2.    Threads do not own resource it share the resource own by the process in which it exist.
3.    Threads communicates each other without the help of OS
4.    Multiple thread processes use fewer resource.

Starvation:- Indefinite waiting of a process that means a process never its change to execute .
Solution of Starvation is Ageing. Ageing is a general concept used to avoid starvation problem. If process is waiting for more time then priority of process will increase.

Inter process Synchronization:- Inter process synchronization is a set of programming interface that allow a programmer to co-ordinate activity among different program process. That can run concurrency in a operating system. Inter process communication methods include pipe and sockets.
This allows a program to handle many user request at the same time.
Process executing concurrently in the operating system may be either independent or co-operating procress.
A process is independent if it can not affected by other processes executing in the system.
A process is co-operating process is that shares data with other process is co-operating process.

These are two types of fundamental model of  Inter process Synchronization (IPS)
      1.    Shared Memory
      2.    Message Passing
Shared Memory:- in this method 2 or more process shared a single chunk of memory to communicate.
Message Passing :- Shared memory created in the kernel.
System call such as send and receive used for communication 
Inter Process Synchronization :- Multilevel process can have  handles to the same event semaphore or time object.
This object to accomplish inter process synchronization. The process that create an object can use the handle referred by the creation function . ex- semaphore , span lock , mutual exclusion.

PROCESS SYNCHRONIZATION
The processes with respect to synchronization are of two types- Co-operating Process & Independent process

The execution of one process affects or affected by other process then there process are said to be co-operating process , otherwise they are said to be Independent process.
Affecting occurs due to shared variable common shared resource /data.
Some Point.
The pre-emption is just a temporary stop, the will come back and continue the execution.
If there any possibility of solution becoming wrong pre-empt by taking the pre-emption.
                 If any solution has the dead lock then process not satisfied 

            Producer consumer problem:-

                               IN- is variable used by producer to identify the next empty slot in the buffer
OUT- is a variable used by consumer to identify the slot from where it has to consume the item
COUNT- is a variable used by consumer and producer to identify the no. of items present in the buffer at any point of time.

CONDITION:-
1.     When the buffer is full , the producer is not allowed to produce item
2.     When the buffer is empty consumer is not allowed to consume the item.



NEXT TOPIC WILL COMING SOON



No comments:

Post a Comment

Recently

All C program

Write a C program to print ‘Hello World’ on screen . #include < stdio.h > #include < conio.h > void  m...