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

Define segmentation, Define Segmentation  The memory allocation method...

Define Segmentation  The memory allocation method subject to “external” fragmentation is Segmentation.

Mutual exclusion variable, Since each thread has its own processing space t...

Since each thread has its own processing space therefore communication between threads will need to be done through a common global variable. Since multiple threads can access the

Need of shift alteration in critical section problem?, Explain with an exam...

Explain with an example the need of Shift Alteration in critical section problem? Consider processes P i and P j and consider the algorithm for P i and P j .

What effect would updating a few byte on the one page, Q. What is the effe...

Q. What is the effect of permitting two entries in a page table to point to the same page frame in memory? Describe how this effect could be used to decrease the amount of time ne

What are the benefits of multiprogramming?, What are the benefits of multip...

What are the benefits of multiprogramming? Responsiveness : Multithreading is an interactive application may permit a program to continue running even if part of it is block

Allocating new pages, Processes have valid and invalid entries on their pag...

Processes have valid and invalid entries on their page tables. The valid entries all point to some where "real" (e.g. a physical page, or some portion of disk in case of non-reside

Draw and r chart and an x-bar chart, Thermostats are subjected to rigorous ...

Thermostats are subjected to rigorous testing before they are shipped to air conditioning technicians around the world. Results from the last five samples are shown in the table. D

Explain the protection problems, Q. In some systems a subdirectory is able...

Q. In some systems a subdirectory is able to be read and written by an authorized user just as ordinary files can be. a. Explain the protection problems that could arise. b.

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