Major locking errors, Operating System

Assignment Help:

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).


Related Discussions:- Major locking errors

Describe virtual memory, What is virtual memory? Virtual memory is a me...

What is virtual memory? Virtual memory is a method that allows the execution of processes that might not be completely in memory. It is the separation of user logical memory fr

Is disk scheduling useful in a single-user environment, Is disk scheduling,...

Is disk scheduling, other than FCFS scheduling, useful in a single-user environment? Explain your answer. In a single-user environment, the I/O queue usually is blank. Requests

Unix, UNIX Shell and History feature. 1.Creating a child process. 2.Creatin...

UNIX Shell and History feature. 1.Creating a child process. 2.Creating a history feature. Its exactly "programming project 1 - Unix Shell and History Feature (p.157-159)" in the Si

List three ways of allocating storage, List three ways of allocating storag...

List three ways of allocating storage, and give advantages of each. a. Contiguous allocation. Fastest, if no changes are to be made. Also simplest for random access files. b

What is thrashing, What is thrashing? It is a method in virtual memory...

What is thrashing? It is a method in virtual memory schemes when the processor spends most of its time swapping pages, rather than implementing instructions. This is because o

PSEUDO CODE FOR PROGRAM, THE PROGRAM WILL CHOOSE TWO RANDOM NUMBERS,THEN PR...

THE PROGRAM WILL CHOOSE TWO RANDOM NUMBERS,THEN PRINT THEM OUT AS AN ADDITION PROBLEM.THE PROGRAM WILL THEN ASK THE USERTO ENTER THE CORRECT ANSWER.IF THE ANSWER IS CORRECT,THE PRO

What is the resident set and working set of a process, What is the resident...

What is the resident set and working set of a process? Resident set is that portion of the process image that is actually in real-memory at a certain instant. Working set is th

Is computers protect the operating system, Q. Some untimely computers prot...

Q. Some untimely computers protected the operating system by placing it in a memory partition that couldn't be modified by either the user job or the operating system itself. Expl

Explain process scheduling in multiprogramming, Normal 0 false ...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd