Major locking errors, Operating System

When programming with threads, there are three very common mistakes that programmers often
make:

1. locking twice (depending on the system and type of lock, can cause crashes, hangs, or do bizarre things);

2. locking and not unlocking (i.e. failure to unlock);

3. deadlock (see next lecture).

4. Priority inversion - This is not an error per se, but an important issue that occurs Of these problems, locking twice is probably the easiest type of error to detect. Here's one example:

function f() { function g() {
lock(L); lock(L);
g(); // access shared data
unlock(L); unlock(L);
} }

So-called "recursive" locks can deal with this situation correctly, though normal locks will cause this thread to wait forever when the function g(), when called fromf(), then calls lock(L) on a previously-held lock. Dealing with this can lead to a common code pattern with certain functions designed only to be called with locks held:

function f(){

function g() {

function g_internal() {
lock(L); lock(L); // locks must be held here!
g_internal(); g_internal(); // access shared data
unlock(L); unlock(L); }
} }

Failure to unlock is slightly more dif?cult to detect. It can occur, for example, if the programmer forgets to release the lock in one of the possible execution branches of the function:

function f() {
lock();
if (x==0) {
// should also unlock here before returning!
return;
}
// do something
unlock();
return;
}

One way to deal with this is just to remember to unlock() at each possible return. Another is to have every return path go through the same section of code (and in C, goto is sometimes useful for this, despite its bad reputation).

Posted Date: 3/12/2013 5:27:26 AM | Location : United States







Related Discussions:- Major locking errors, Assignment Help, Ask Question on Major locking errors, Get Answer, Expert's Help, Major locking errors Discussions

Write discussion on Major locking errors
Your posts are moderated
Related Questions
Explain the Proper Distribution of Functionality and Code It is important to note that the bandwidth of the server operating system and server processor availability is fixed.

Explain bounded buffer and unbounded buffer. Here in a producer-consumer problem the producer process produces information that is consumed by a consumer process. At this time

List operations to be performed on directories. Search for a file, delete a file, create a file, list a directory, rename a file, and traverse the file system.

Explain the difference between internal and external fragmentation. Internal Fragmentation is the area in a region or a page that is not used by the job occupying that region o

Q. Could you replicate a multilevel directory structure with a single-level directory structure in which arbitrarily long names can be used? If your answer is yes describe how you

The Most comman difference are given below System calls are heavy. While a procedure call can generally be performed in a few system instructions, a system call needs the c

Remote IT Support Engineer Windows Systems Administrator Project Description: Need Windows base IT Support Engineer / Systems Network Administrator - perfectly MCSE qualified

Which is most common phase structured grammar? Most common phase structured grammar is Context – Sensitive

linked allocation using i node

A Unix shell is a shell or command-line interpreter that gives a traditional user interface for the Unix-likesystems and for Unix operating system. Users operates the operation of