multiprocessing -interprocessing communication and process sunchronization,semaphore
DESCRIPTION
Multiprocessing In high performance computing Inter processing communication Process Synchronziation Synchronization with semaphoreTRANSCRIPT
![Page 1: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/1.jpg)
INTERPROCESSOR COMMUNICATION AND
PROCESS SYNCHRONIZATION
Presented ByNeena R Krishna
S8,BTECH CSESNGIST
![Page 2: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/2.jpg)
CONTENTS
• INTRODUCTION• INTERPROCESSOR COMMUNICATION• PROCESS SYNCHRONIZATION AND
SEMAPHORE
![Page 3: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/3.jpg)
INTRODUCTION
• Independent process cannot affect or be affected by the execution of another process
• Cooperating process can affect or be affected by the execution of another process
• Advantages of process cooperation – Information sharing – Modularity – Convenience
![Page 4: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/4.jpg)
Interprocessor Communication• Exchange of data between two or more processes.– Os provide facilities for IPC. • IPC facility provides two operations:
send(message)and receive(message) (message size fixed or
variable). • If P and Q wish to communicate, they need to:–establish a communication link between them
exchange messages via send/receive
![Page 5: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/5.jpg)
Contd..
• Multiprocessor and multiple memory modules are connected together via some interconnection network.
• They fall on two categories:-1)Shared memory2)Message passing
![Page 6: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/6.jpg)
INTERPROCESSOR COMMUNICATION THROUGH ADDRESS SPACE SHARING
![Page 7: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/7.jpg)
INTERPROCESSOR COMMUNICATION VIA KERNAL SPACE
![Page 8: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/8.jpg)
SHARED MEMORY
• Processors exchange information through their central shared memory system.
• Inter co-ordination through a global memory shared by all processor.
• Server system that communicate through a bus and cache memory controller.
• Access to shared memory is balanced – Symmetric multiprocessor
![Page 9: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/9.jpg)
Contd..
• Each processor has equal opportunities to read/write to memory including equal access speed.
PROCESSORs
Registers
Local memory banks (additional memory resource
Cache
Buffers
![Page 10: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/10.jpg)
![Page 11: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/11.jpg)
![Page 12: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/12.jpg)
Contd..
• Basic issues in the design of shared memory system have to be taken in consideration :-1)Access Control2)Synchronization3)Protection and Security
![Page 13: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/13.jpg)
ACCESS CONTROL
• Determines which process access are possible to which resource.
• The latter contain flag that determine the legality of each access attempt.
• If there are access attempt to resources then until the desired access is completed, all disallowed access are attempt and illegal process are blocked.
![Page 14: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/14.jpg)
SYNCHRONIZATION
• Constraints limit the time of access from sharing processes to shared resource.
• Appropriate synchronization ensures that the information flows properly and ensure system functionality.
![Page 15: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/15.jpg)
PROTECTION AND SECURITY
• It is a system feature that prevents processes from making arbitrary access to resource belonging to other processes.
• Sharing and protection are incompatible:-– Sharing allow access & protection restricts it.
![Page 16: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/16.jpg)
FEATURES
• All communications are done using implicit loads and stores to a global address space.
• Synchronization and communication are distinct.
![Page 17: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/17.jpg)
MESSAGE PASSING
• Combine the local memory and processor at each node of the interconnection network.
• There is no global memory.– Move data from one local memory to another by
means of message passing.– Done by a send/reciever pair of commands and
dealing consistency issues.– Eg: c.1990 Ncube.
![Page 18: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/18.jpg)
![Page 19: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/19.jpg)
Contd..
• A node in message passing system of processor and its local memory.
• They are able to store message buffers and able to perform send/receive operation at the same time as processing.
• Processor do not share a global memory and each processor has access to its own address space.
![Page 20: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/20.jpg)
• Basic advantage :-– Scalable.
![Page 21: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/21.jpg)
SYNCHRONIZATION
• Required when one process must wait for another to complete some operation before proceeding.– Eg:-one process (called a writer) may be writing
data to a certain main memory area, while another process (a reader) may be reading data from that area and sending it to the printer. The reader and writer must be synchronized so that the writer does not overwrite.
![Page 22: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/22.jpg)
IMPORTANCE OF SYNCHRONIZATION
• Prevention and elimination of race conditions, deadlocks and starvation.
• Data integrity/consistency.• Collaboration.• Efficiency.
![Page 23: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/23.jpg)
SYNCHRONIZATION PROBLEMS
• Race conditions– the exact timing in the execution of concurrent
processes is critical• Critical sections– part of a program that must be protected from
interference– usually resolved via mutual exclusion
• Mutual exclusion– the usage of resources by processes is restricted– usually: only one process may use one instance of a
resource
![Page 24: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/24.jpg)
RACE CONDITION
![Page 25: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/25.jpg)
TYPES OF SYNCHRONIZATION
• Barrier • Lock• Semaphore
![Page 26: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/26.jpg)
BARRIER
• Usually implies that all tasks are involved• Each task performs its work until it reaches
the barrier. It then stops, or "blocks".• When the last task reaches the barrier, all
tasks are synchronized.• What happens from here varies. Often, a serial
section of work must be done. In other cases, the tasks are automatically released to continue their work.
![Page 27: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/27.jpg)
LOCKSuppose there are 2 processes – Write-process 1 and Read-process 2
PROCESS 1
WRITE
MEMORY LOCKED
AFTER WRITING
UNLOCK MEMORY
PROCESS 2
READ
![Page 28: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/28.jpg)
Contd..• The LOCK(x) operation may be implemented
as follows:Var x:shared integer;LOCK (x):beginvar y: integer;y x;
While y =1 do yx;//wait until gate is open //x1 //set gate to unavailable status //end
![Page 29: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/29.jpg)
• The UNLOCK(x) operation may be implemented as
UNLOCK(x): x 0;
![Page 30: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/30.jpg)
SEMAPHORE
• It is a resource that contains an integer value and allows process to synchronize by testing and setting this value on a single atomic operations.– Process that test the value of a semaphore and
sets it to a different value,is guaranteed no other process will interfere with the operation in the middle.
![Page 31: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/31.jpg)
Contd..
• Two types of operations :-– Wait– Signal.
![Page 32: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/32.jpg)
FEATURES OF SEMAPHORE• Semaphores are used to synchronize operations
when processes access a common, limited, and possibly non-shareable resource.
• Each time a process wants to obtain the resource, the associated semaphore is tested. A positive, non-zero semaphore value indicates the resource is available.
• Semaphore system calls will, by default, cause the invoking process to block if the semaphore value indicates the resource is not available
![Page 33: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/33.jpg)
TYPES OF SEMPAHORE
• COUNTING SEMAPHORE– Semaphores controlling access to N (multiple)
resources, thus assuming a range of non-negative values, are frequently.
• BINARY SEMAPHORE– Semaphores that control access to a single
resource, taking the value of 0 (resource is in use) or 1 (resource is available).
![Page 34: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/34.jpg)
SEMAPHORE IMPLEMENTATION
![Page 35: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/35.jpg)
![Page 36: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/36.jpg)
var s: semaphoreP(s): MUTEXBEGIN (s) s s-1; If s < 0 then begin Block the process executing the P(s) and
put it in a FIFO queue associated with the semaphore s;
end MUTEXEND
![Page 37: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/37.jpg)
V(s): MUTEXBEGIN (s) SS + 1; If s < 0 then begin if an inactive process associated with
semaphore s exists, then wake up the highest priority blocked process associated with s and
put it in a ready list. end MUTEXEND
![Page 38: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/38.jpg)
EXAMPLE
PRODUCER CONSUMER PROBLEMProducerWhile(true){
while(((in+1) % Buffer_Size)==out);buffer[in]=item;in=(in+1)%Buffer_Size;
}
![Page 39: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/39.jpg)
Contd..
ConsumerWhile(true){
while(in==out);item=buffer[out];out=(out+1)%Buffer_Size;return item;
}
![Page 40: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/40.jpg)
Contd..
![Page 41: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/41.jpg)
Solution with Semaphore
Empty=n,full=0.mutex=1ProducerDo{
//Produce itemwait(empty);wait(mutex);//add item to the buffersignal(mutex);signal(full);
}while(true);
![Page 42: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/42.jpg)
Contd..
ConsumerDo{
wait(full);wait(mutex);//Remove an item from buffersignal(mutex);signal(empty);//consume the remove item
}while(true);
![Page 43: Multiprocessing -Interprocessing communication and process sunchronization,semaphore](https://reader035.vdocuments.net/reader035/viewer/2022062319/55643e40d8b42ad3308b5339/html5/thumbnails/43.jpg)