Question

Is is possible to implement locks for a critical section in user-level code without the use...

Is is possible to implement locks for a critical section in user-level code without the use of system calls or atomic instructions? Justify your answer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Yes it is possible to implement locks for a critical section in user-level code without use of system calls or atomic instructions. There are many examples like Peterson's algorithm and Dekker's algorithm.

I am discussing Peterson's algorithm as a justification of my answer. Although I will be discussing Peterson's algorithm which is a 2-process synchronization algorithm, it can be modified for more than 2-process. This answer is known as Filter algorithm.

Peterson's Algorithm:

There are two variables, flag and turn. A flag[n] value of true indicates that the process n wants to enter the critical section. Entrance to the critical section is granted for process P0 if P1 does not want to enter its critical section or if P1 has given priority to P0 by setting turn to 0.

                    bool flag[2] = {false, false};

                    int turn;

P0:              flag[0] = true;

                   P0_gate: turn = 1;

                   while (flag[1] == true && turn == 1)

                   {

                   // busy wait

                   }

                   // critical section

                   ...

                   // end of critical section

                   flag[0] = false;

P1:              flag[1] = true;
                 P1_gate: turn = 0;
                 while (flag[0] == true && turn == 0)
                 {
                 // busy wait
                 }
                 // critical section
                 ...
                 // end of critical section
                 flag[1] = false;

The algorithm satisfies the 4 essential criteria to solve the critical section problem, provided that changes to the variables turn, flag[0], and flag[1] propagate immediately and atomically. The 4 criteria are mutual exclusion, progress, bounded waiting and platform independent. The while condition works even with preemption.

Since turn can take on one of two values, it can be replaced by a single bit.

Mutual exclusion

P0 and P1 can never be in the critical section at the same time: If P0 is in its critical section, then flag[0] is true. In addition, either flag[1] is false (meaning P1 has left its critical section), or turn is 0 (meaning P1 is just now trying to enter the critical section, but graciously waiting), or P1 is at label P1_gate (trying to enter its critical section, after setting flag[1] to true but before setting turn to 0 and busy waiting). So if both processes are in their critical sections then we conclude that the state must satisfy flag[0] and flag[1] and turn = 0 and turn = 1. No state can satisfy both turn = 0 and turn = 1, so there can be no state where both processes are in their critical sections. (This recounts an argument that is made rigorous in.)

Bounded waiting

Bounded waiting, or bounded bypass means that the number of times a process is bypassed by another process after it has indicated its desire to enter the critical section is bounded by a function of the number of processes in the system. In Peterson's algorithm, a process will never wait longer than one turn for entrance to the critical section: After giving priority to the other process, this process will run to completion and set its flag to 1, thereby never allowing the other process to enter the critical section...

Progress

Progress is defined as the following: if no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in making the decision as to which process will enter its critical section next. Note that for a process or thread, the remainder sections are parts of the code that are not related to the critical section. This selection cannot be postponed indefinitely. A process cannot immediately re-enter the critical section if the other process has set its flag to say that it would like to enter its critical section.

Platform Independent

It is platform independent because there is no kernel or hardware related mechanism used in this solution.

Add a comment
Know the answer?
Add Answer to:
Is is possible to implement locks for a critical section in user-level code without the use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a)Given the following solution for the critical section problem for two processes (the code shown is for processes Pi),...

    a)Given the following solution for the critical section problem for two processes (the code shown is for processes Pi), show why it does not satisfy the mutual exclusion requirement. Here,lock is a shared variable initialized to FALSE. (Hint: Indicate one scenario where the mutual exclusion requirement is violated.) do {            lock = FALSE;           while (lock);           lock = TRUE         Critical section           /Empty section                   Remainder section } (b)Does this satisfy the progress requirement? Justify your answer

  • The program is written in c. How to implement the following code without using printf basically...

    The program is written in c. How to implement the following code without using printf basically without stdio library? You are NOT allowed to use any functions available in <stdio.h> . This means you cannot use printf() to produce output. (For example: to print output in the terminal, you will need to write to standard output directly, using appropriate file system calls.) 1. Opens a file named logfle.txt in the current working directory. 2. Outputs (to standard output usually the...

  • pleasw answer as soon as possible . this is for my exam practice . please read...

    pleasw answer as soon as possible . this is for my exam practice . please read the code and answer the question In a system, there are multiple reader processes which read from a shared file and multiple writer processes which update a shared file. The following variables are shared among all processes: int readCounter; semaphore mutex, writeLock; Reader and writer processes are given in the following C++-like pseudo programs: Reader Process // Non-Critical Section P(mutex); Writer Process // Non-Critical...

  • Use MIPS memory-mapped I/O to interact with a user. Each time the user presses a button,...

    Use MIPS memory-mapped I/O to interact with a user. Each time the user presses a button, a pattern of your choice displays on five light-emitting diodes (LEDs). Suppose the input button is mapped to address 0xFFFFFF10 and the LEDs are mapped to address 0xFFFFFF14. When the button is pushed, its output is 1; otherwise, it is 0. (a) Write MIPS code to implement this functionality. (b) Draw a schematic for this memory-mapped I/O system. (c) Write HDL code to implement...

  • The following code fragment is a 2-process "solution" to the critical section problem try ] =...

    The following code fragment is a 2-process "solution" to the critical section problem try [i] = true ; while (incs[j]) no-op; while (turn=j and try[j]) no-op; incs [i] = true ; critical section try [i] = false; incs [i] = false; turn = j ; Does the above "solution" meet all 3 conditions of critical sections? Please explain your answer.

  • TRUE-FALSE     Basic synchronization principles and multithreading 1. Java user threads can implement both busy-waiting and no-busy-waiting...

    TRUE-FALSE     Basic synchronization principles and multithreading 1. Java user threads can implement both busy-waiting and no-busy-waiting policy. 2. Priority inversion avoids deadlocks. 3. Spinlock mutex can be used as an adaptive mutex. 4. Java RTE can be blocked for Input/Output operation. 5. Interrupted user thread, which executes a method in a monitor, must be rolled back to undo any changes it performed. 6. The synchronization primitive by disabling interrupts can be used by an application program. 7. Bounded-waiting requirement is...

  • use python to do it implement the tic-tac-toe game. What to submit: 1. Your source code...

    use python to do it implement the tic-tac-toe game. What to submit: 1. Your source code 2. Two runs, one user wins and one user loses.

  • use MATLAB and PLZ comment the code so that it is easy to understand Implement the...

    use MATLAB and PLZ comment the code so that it is easy to understand Implement the following series of sinusoidal signals in MATLAB: 1 sin(kt) where N 30 k=1 x(t) k 1 Write a MATLAB script which does the following steps First define and plot signal sin(t) for 0 St s 3Twhere T is the fundamental period of this signal The signal you just implemented is x(t) with N 1 a. Then modify your code to be able to define...

  • For a confidence level of 92%, find the critical value Question 5. Points possible: 1 This...

    For a confidence level of 92%, find the critical value Question 5. Points possible: 1 This is attempt of Out of 500 people sampled, 280 had kids. Based on this, construct a 99% confidence interval for the true population proportion of people with kids. Give your answers as decimals, to three places <p Question 6. Pos t In a recent poll, 410 people were asked if they liked dogs, and 47% said they did. Find the margin of error of...

  • Write MIPS code for each of the following instructions, Your assembly should implement the C code...

    Write MIPS code for each of the following instructions, Your assembly should implement the C code directly – i.e.,do not ’optimize’ the C code to change the order of operations or reduce computations. Use commands only like add, sub, lw, sw, immediate Part 1. x = 3-13*x; Do not use multiply. One way of doing the multiply without a multiply instruction is by using many add instructions (x+x+...+x). For this problem, you should do it with fewer additions. Hint: We...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT