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
Which android version is available till now

The following is a dump of a TCP header in hexadecimal format: 00CD0018 00000EF1 00000D5D 502200D1 01BF0010 We need to first split the above hex as such 00 CD 00 18 00 00

Q. Is disk scheduling except FCFS scheduling useful in a single-user environment? describe your answer. Answer: In a single-user environment the I/O queue typically is empty.


Write note on process, process state? A process is in excess of the program code which is sometimes known as text section. It as well includes the current activity as represent

Question 3: (a) Fincorp Ltd is an insurance company wishing to change over to a better business system using an improved version of a financial information system (FIS). The direc

Short term scheduling The short term scheduler as well known as the dispatcher executes most frequently and makes the fine grained decision of which process to execute next. Th

The different paging techniques are 1. Multilevel paging or hierarchical paging method: In definite cases the page table may consist up to 1 million entries. This would be

Explain system-wide open-file and per-process open-file The system-wide open-file table have a copy of the FCB of each open file, as well as other information. The per-pr

Referring to Figure below, discuss how you would alter the circuit to obtain: 1. a straightforward amplifier with gain 1, 2. a straightforward amplifier with gain 10, 3. a