Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 . This problem studies the interaction between real - time scheduling and mutual exclusion. Consider the following excerpt of code: 1 pthread _ mutex

3. This problem studies the interaction between real-time scheduling and mutual exclusion.
Consider the following excerpt of code:
1 pthread_mutex_t X; // Resource X: Radio communication
2 pthread_mutex_t Y; // Resource Y: LCD Screen
3 pthread_mutex_t Z; // Resource Z: External Memory (slow)
4
5 void ISR_A(){// Safety sensor Interrupt Service Routine
6 pthread_mutex_lock(&Y);
7 pthread_mutex_lock(&X);
8 display_alert(); // Uses resource Y
9 send_radio_alert(); // Uses resource X
10 pthread_mutex_unlock(&X);
11 pthread_mutex_unlock(&Y);
12}
13
14 void taskB(){// Status recorder task
15 while (1){
16 static time_t starttime = time();
17 pthread_mutex_lock(&X);
18 pthread_mutex_lock(&Z);
19 stats_t stat = get_stats();
20 radio_report( stat ); // uses resource X
21 record_report( stat ); // uses resource Z
22 pthread_mutex_unlock(&Z);
23 pthread_mutex_unlock(&X);
24 sleep(100-(time()-starttime)); // schedule next excecution
25}
26}
27
28 void taskC(){// UI Updater task
29 while(1){
30 pthread_mutex_lock(&Z);
31 pthread_mutex_lock(&Y);
32 read_log_and_display(); // uses resources Y and Z
33 pthread_mutex_unlock(&Y);
34 pthread_mutex_unlock(&Z);
35}
36}
You may assume that the comments fully disclose the resource usage of the procedures. That
is, if a comment says uses resource X, then the relevant procedure uses only resource X. The
scheduler running aboard the system is a priority-based preemptive scheduler, where taskB is
higher priority than taskC. In this problem, ISR A can be thought of as an asynchronous task
with the highest priority.
The intended behavior is for the system to send out a radio report every 100ms and for the
UI to update constantly. Additionally, if there is a safety interrupt, a radio report is sent
immediately and the UI alerts the user.
(a) Every so often, when there is a safety interrupt, the system completely stops working.
In a scheduling diagram (like Figure 12.11 in Lee&Seshia), using the tasks fA,B,Cg, and
resources fX,Y,Zg, explain the cause of this behavior. Execution times do not have to
be to scale in your diagram. Label your diagram clearly. You will be graded in part on
the clarity of your answer, not just on its correctness.
(b) Using the priority ceiling protocol, show the scheduling diagram for the same sequence
of events that you gave in part (a). Be sure to show all resource locks and unlocks until
all tasks are finished or reached the end of an iteration. Does execution stop as before?
(c) Without changing the scheduler, how could the code in taskB be reordered to fix the
issue? Using an exhaustive search of all task/resource locking scenarios, prove that
this system will not encounter deadlock. (Hint: Your proof should enumerate 6 cases
because the 3 tasks each have 2 possible resources they could block on.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is a full-service agency?

Answered: 1 week ago

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago