What is the difference between Semaphores and Locks?

What is the difference between Semaphores and Locks?

Monitors and Condition variables

Monitors are some procedures, variables, and data structures grouped together in a package. If a process cannot enter the monitor it must block itself. This operation is provided by
the condition variables.

Processes Locks

Locks are another synchronization mechanism. A lock has got two atomic operations (similar to semaphore) to provide mutual exclusion. These two operations are Acquire and Release.

Sleeping Barber Problem

sample solution for the sleeping barber problem

Dining Philosophers Problem

Here’s a solution for the Dining Philosophers Problem which does not require a process to write another process’s state, and gets equivalent parallelism.

Readers and Writers Problem

The readers/writers problem is one of the classic synchronization problems. It is often used to compare and contrast synchronization mechanisms.

Producers/Consumers Problem

Producer – Consumer processes are common in operating systems. The problem definition is that, a producer (process) produces the information that is consumed by a consumer (process).

Semaphores

Semaphores provide a much more organised approach to controlling the interaction of multiple processes than would be available if each user had to solve all interprocess communications using simple variables, but more organization is possible.

Bakery Algorithm

Bakery algorithm handles critical section problem for n processes

Dekker’s solution for Mutual Exclusion

Mutual exclusion can be assured even when there is no underlying mechanism such as the test-and-set instruction. This was first realised by T. J. Dekker and published (by Dijkstra) in 1965. Dekker’s algorithm uses busy waiting and works for only two processes.

Critical Sections: The Mutex Solution

A critical section is a part of a program in which is it necessary to have exclusive access to shared data. Only one process or a thread may be in a critical section at any one time.

Mutexes: Mutual Exclusion

Mutual exclusion can be achieved by a system of locks. A mutual exclusion lock is colloquially called a mutex. You can see an example of mutex locking in the multithreaded file reader

Serialization

The key idea in process synchronization is serialization. This means that we have to go to some pains to undo the work we have put into making an operating system perform several tasks in parallel.

Interprocess synchronization

All processes prevent casual exchange of data. However, occasionally two processes might need to communicate with each other. One method that enables processes to communicate is called interprocess synchronization.

What are the process states in Unix?

What are the process states in Unix?

keep looking »