Major locking errors, Operating System

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

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() {
if (x==0) {
// should also unlock here before returning!
// do something

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
Q. Process migration in a heterogeneous network is typically impossible given the differences in architectures and operating systems. Explain a method for process migration across

Define Latency plus seek time The total time to arrange a disk drive mechanism for a block of data to be read from is its Latency plus seeks time

Q. Explain about Functions of Operating System? Functions of Operating System Operating system performs 3 functions as follows: 1.  Convenience:   Operating System mak

Define the Division of Labour between Client and Server Given our definition of client - server as the interaction between dispersed application logic components it must be not

IMPLEMENTATION OF SEGMENTATION WITH AN EXAMPLE Segmentation is a memory-management scheme that represents the user view of memory. A logical address space is the collection of

What are the characteristics of SRS? i. Correct - The SRS should be made up to date when appropriate requirements are identified. ii. Unambiguous - When the requirements are

Describe the differences among short-term, medium-term, and long-term scheduling.   Short-term (CPU scheduler)-selects from jobs in memory those jobs that are ready to execu

What is a Process Control Block? Every process in the operating system is represented by a process control block as well called a task control block. It contains several pieces

Explain the steps in deadlock recovery. a)      Exterminate off all processes involved - drastic. b)      Exterminate off one at a time till deadlock gone - select a victim.