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

Identify the binding and non-binding constraints, Crumbles Bakery needs to ...

Crumbles Bakery needs to decide how many and what types of cupcakes to make today. Currently, they make two types of cupcakes: chocolate cupcakes and carrot cake cupcakes. Chocolat

Queing theory, how to solve queing theory step by step

how to solve queing theory step by step

Business, why some companies do not pay sufficient attention to staff induc...

why some companies do not pay sufficient attention to staff induction

Multiprogramming, how response times are reduced by allowing time sharing o...

how response times are reduced by allowing time sharing on top of multiprogramming

Define secondary memory, Define secondary memory. This memory holds tho...

Define secondary memory. This memory holds those pages that are not there in main memory. The secondary memory is usually a high speed disk. It is called as the swap device, an

Explain message passing system, Message passing system:- The function o...

Message passing system:- The function of message system is to permit processes to communicate with one another without the requirement to resort (option) to shared data. Commun

Define the term system software, Question: (a) Define the term system ...

Question: (a) Define the term system software and application software, giving an example for each. (b) Draw a diagram to represent the abstract view of a computer system i

How is the NTFS namespace planned, Q. How is the NTFS namespace planned? Ex...

Q. How is the NTFS namespace planned? Explain. Answer: The NTFS namespace is prearranged as a hierarchy of directories where every directory uses a B+ tree data structure to

Define the client - server communications environment, Define the Client - ...

Define the Client - Server Communications Environment Today's client - server communications environment offers programmers great flexibility for application design. Applicatio

How program execute in operating system, Q. How Program execute in operatin...

Q. How Program execute in operating system? Program execution: Operating system loads a program in memory and executes the program. The program should be able to end its exec

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