“Language Mechanism for Synchronization” Poornima Institute of Engineering & Technology, Jaipur Department of Computer Engineering A Presentation on Presented by,: Manish Bhardwaj Assistant Professor “Language Mechanism for Synchronization” Lecture No-15 Subject Code -8 CS3 Subject Name- Ds
Language Mechanisms for Synchronization Concurrent programming allows for : concurrent processing with some specifications. Allows for synchronization to communicate.
Language Mechanisms for Synchronization Language constructs Shared Variable Synchronization Semaphore : A shared-variable and system call approach Monitor: A Data Type Abstraction Approach Conditional Critical Region : A control Structure Approach Serializer : A combined Data Abstraction and Control Structure Approach Path Expression: A Data Abstraction and Program Structure Approach
Language Mechanisms for Synchronization Message Passing Synchronization Asynchronous Message Passing Synchronous Message Passing Communicating Sequential Processes: An Input / Output Approach Remote Procedure Call : A Procedure Call and Asymmetrical Communication Approach Ada Rendezvous : A Procedure Call and Symmetrical Communication Approach
Difference in Sequential and Concurrent Language Specification of concurrent activities Synchronization of processes Interprocess communication Nondeterministic execution of processes
Language Constructs for Procedural Languages Program Structure Data Structures Control Structures Procedures and System Calls Input and Output Assignments
Program Structure How programs and subcomponents of program (procedures. Variables. Constants. Statements, blocks , expressions ,terms, etc) are managed. Sequential execution is assumed until control statements are altered explicitly.
Data Structures Represent Objects , Data Type abstraction and efficient implementation ways.
Control Structures Regulates program execution flow. One-in-one-out control structure mechanism is used generally. For example if-then-else, repeat-until, while-do etc. Subroutine calls. Returns and exit are also used.
Procedures and System calls Responsible for flow of execution. Parameter passing Activation of special routines Activation of system services
Input and Output Responsible for Results of program execution. Message Passing communication can be used for input output.
Assignments Responsible for Side effects for data objects. State of program executions.
Shared Variable Synchronization Responsible for Synchronization of concurrent processes in a centralized operating system. Arrangement of sharing variables. Simulation of shared variable synchronization by message passing rather than message passing or client server communication directly.
Shared Variable Synchronization Semaphore : A Shared- variable and System Call Approach Semaphore is : Built in System Data Type. A variable Lock is acquired and released for synchronization. Provides most primitive locking mechanisms only. Drawback is loss of transparency.
Shared Variable Synchronization Semaphore : A Shared- variable and System Call Approach Example: the Reader/Writer Problems synchronization + concurrency if DB empty, allow anyone in if reader in DB, writer not allowed in if writer in DB, nobody allowed in
Shared Variable Synchronization Semaphore : A Shared- variable and System Call Approach
Shared Variable Synchronization Semaphore : A Shared- variable and System Call Approach Example: the Reader/Writer Problems synchronization + concurrency Variations Reader preference Allow a reader in if other readers are in Strong reader preference Allow readers in when writer leaves Weak reader preference When writer leaves, select a process at random
Shared Variable Synchronization Semaphore : A Shared- variable and System Call Approach Example: the Reader/Writer Problems synchronization + concurrency Variations Weaker writer preference Allow a writer in when writer leaves Writer preference Do not allow readers in if writer is waiting
Shared Variable Synchronization Semaphore : A Shared- variable and System Call Approach Semaphore solution to the weak reader preference problem
Semaphore solution to the weak reader preference problem var mutex=1, db=1: semaphore; rc=0: integer reader processes writer processes do (forever) BEGIN otherStuff() P(mutex) rc := rc + 1 if rc = 1 then P(db) P(db) V(mutex) read database write database rc := rc -1 if rc = 0 then V(db) V(db) END
Shared Variable Synchronization Monitor: A Data Type Abstraction Approach Loss of transparency removed Object Model Concept Consists of procedures , declarations for local variables and initialization procedures. Only one object can be active at a time. More Structured than Semaphore Wait and Signal are used for coordination.
Monitor solution to weak reader preference problem
Shared Variable Synchronization Conditional Critical Region: A Control Structure Approach Drawback in monitor is need of procedure to be exclusive and concurrent too. Structured version of Semaphore. Critical section codes are expressed by region-begin-end. When predicate is used for testing a condition. Drawback of CCR is infeasibility of Separate compilation and common address space.
Shared Variable Synchronization Conditional Critical Region: A Control Structure Approach
Shared Variable Synchronization Serializer: A Combined Data Abstraction and Control Structure Approach Drawback in monitor is need of procedure to be exclusive and concurrent too. Serializer is the solution. It Provides 2 regions , one provides mutual exclusion and other allow concurrency (Hollow Region). Joincrowd-then-begin-end structure is used.
Shared Variable Synchronization Path Expression: A Data Abstraction and Program Structure Approach Abstraction of Data type. Procedures in abstract data type donot contain any explicit reference to any synchronization. Order of execution must follow the constraints imposed by path expressions. It Specifies the way to define the operation invocation for a shared object.
Synchronization mechanisms and Language Facilities
Message Passing Synchronization Asynchronous: non-blocking send, blocking receive Synchronous: blocking send, blocking receive
Message Passing Synchronization Asynchronous Message Passing
Message Passing Synchronization Synchronous Message Passing
Message Passing Synchronization Communicating Sequential Process: An Input / Output Approach
Message Passing Synchronization Ada Rendezvous: A Procedure Call and Symmetrical Communication Approach
Object Model Resource Servers Resource manager is responsible for use of shared resources.
Object Model Resource Servers