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
What is long-term, medium-term, short-term? In a batch system many processes are submitted than are able to be executed immediately. These processes are reel to a mass storage

Q. What is Multiprogramming? Multiprogramming When two or more programs are in memory at the same instance, sharing the processor is referred to multiprogramming opera

What is page fault and what are the steps taken by the OS to remove page fault? A page fault is caused while a page that hasn't been brought into memory is being addressed. The

Explain Swapping Swapping is a method of temporarily removing inactive programs from the memory of computer system.

FCFS (First Come, First Served) Perform operations in order requested No reordering of work queue No starvation every demand is serviced Poor performance

Question: a) Illustrate with the help of a diagram, the difference between two tier and three tier architectures. b) Explain in what kind of environment, a peer to peer envi

Consider the following C program where M, N, K are predefined constants. Assume int is 4 bytes. Suppose this program is run on a machine with 4KB page size and 32 TLB entries. Init

Write note on process, process state? A process is in excess of the program code which is sometimes known as text section. It as well includes the current activity as represent

What is page fault? In the computer storage technology a page fault is an exception which is raised by the memory management unit when a requested page isn't mapped in physical

W hat is hashed page table & method of hashed page table with details