What is race condition in OS and provide a possible solution to it? Explain using the example below.
Added by Daniel B.
Step 1
This can lead to inconsistent or unexpected results, as the processes may interfere with each other. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 55 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
A race condition occurs when two or more threads can access shared data and they try to change it concurrently. Because the kernel can swap between threads at any time, you don't know the order in which the threads will attempt to access the shared data. In the following, we will create a program that stores a global variable, global, initialized to 0.We also create two pThreads that attempt to access the shared variable. thread1 is a thread that increments global 90,000,000 times, while thread2 concurrently decrements global the same number of times. 1. What is the expected value of global when both threads have finished executing?
Akash M.
5. Give an example in pseudo-code of 3 processes that use semaphores such that, according to the order in which they are executed, can either: terminate normally; or deadlock. Remember to indicate how the semaphores are initialized. 6. Insert semaphores to satisfy the properties: P1: print(A); print(B); print(C); P2: print(E); print(F); print(G); * print A before printing F * print F before printing C Don't forget to indicate the initial value of the semaphores. 7. Insert semaphores such that only ACERO or ACREO is printed. P1: print(C); print(E); P2: print(A); print(R); print(O); Don't forget to indicate the initial value of the semaphores. 8. Assuming semaphores SA, SB, and SC are initialized at 0, what strings can be printed? P1: repeat print(A); SC.V; SA.P; forever P2: repeat print(B); SC.V; SB.P; forever P3: repeat SC.P; SC.P; print(C); SA.V; SB.V; forever 9. Explain why interrupts are not appropriate for implementing synchronization primitives in multiprocessor systems. 10. What is the meaning of the term busy waiting? What other kinds of waiting are there in an operating system? Can busy waiting be avoided altogether? Explain your answer. 11. Consider the version of the dining-philosophers problem in which the chopsticks are placed at the center of the table and any two of them can be used by a philosopher. Assume that requests for chopsticks are made one at a time. Describe a simple rule for determining whether a particular request can be satisfied without causing deadlock given the current allocation of chopsticks to philosophers.
Using the picture below, will there be any deadlock if the order of the downs were switched, for producer or for consumers individually as well as together (so 3 combinations)? Explain. Thanks!
Aarya B.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD