Locks - mutexes, Operating System

Locks (also known as mutexes, short for mutual exclusion locks) provide mutual exclusion to shared data inside a critical session. They are implemented by means of two atomic routines:

acquire, which waits for a lock, and takes it when possible; and release, which unlocks the lock and wakes up the waiting threads. The rules for using locks/mutexes are the following:

1. only one person can have the lock;

2. locks must be acquired before accessing shared data;

3. locks must release after the critical section is done;

4. locks are initially released.

The syntax for using locks in C/C++ is the following:

update data // this is the critical section

Let us now try to rewrite the "Too Much Milk" problem in a simpler, cleaner, more symmetric, and portable way, using locks. In order to do so, the code for Thread A (and also for Thread B) would be the following:

if (no milk)
buy milk

Posted Date: 3/12/2013 5:14:02 AM | Location : United States

Related Discussions:- Locks - mutexes, Assignment Help, Ask Question on Locks - mutexes, Get Answer, Expert's Help, Locks - mutexes Discussions

Write discussion on Locks - mutexes
Your posts are moderated
Related Questions
Q. Name two differences between logical and physical addresses? Answer: A logical address doesn't refer to an actual existing address rather it refers to an abstract address in

write a linux command to display lines from 25 - 45 of directory "/edc/password" write a linux command to display directory in /edc

Direct communication With direct communication each process that requires to communicate must explicitly name the recipient or sender of the communication. The send and receive

Explain about paging? Answer: Paging is a memory-management scheme that permits the physical-address space of process to be noncontiguous. Paging avoids the considerable proble

list trhe various classification of model and types?

explain simple segmentation

1. How is reliability enhanced with the microkernel approach to system design?  2. In a virtual machine design where guest operating systems are independent virtual machines sup

Write a short note on PCB? Every process is represented in the operating system by a process control block also called a task control block. It contains more information regard

The optimal replacement policy, called OPT, is to evict the page which will be accessed farthest into the future. Since we can't predict the future precisely, we can't implement OP