首页 > > 详细

EL-GY 6483讲解、c/c++,Java编程语言辅导、讲解Python 辅导留学生Prolog|讲解SPSS

EL-GY 6483
Scheduling 2
1. Suppose the functions work_t1(), work_t2(), and work_t3() are called from different threads. Which
of the examples below could potentially lead to deadlock of these threads? For each code sample that
may deadlock, give an example of a schedule (ordering of events) that would result in deadlock.
(a) mutex_t a;
mutex_t b;
void work_t1() {
lock(&a);
lock(&b);
// critical section using resources
// protected by a and b
unlock(&b);
unlock(&a);
}
void work_t2() {
lock(&a);
// critical section using resources
// protected by a
unlock(&a);
}
void work_t3() {
lock(&b);
// critical section using resources
// protected by b
unlock(&b);
}EL-GY 6483
(b) mutex_t a;
mutex_t b;
void work_t1() {
lock(&a);
lock(&b);
// critical section using resources
// protected by a and b
unlock(&b);
unlock(&a);
}
void work_t2() {
lock(&b);
lock(&a);
// critical section using resources
// protected by a and b
unlock(&a);
unlock(&b);
}
(c) mutex_t a;
mutex_t b;
void ordered_lock(mutex_t *l1, mutex_t *l2) {
// grab locks in high-to-low address order
if (l1 > l2) {
lock(l1);
lock(l2);
} else {
lock(l2);
lock(l1);
}
}
void work_t1() {
ordered_lock(&a,&b);
// critical section using resources protected by a and b
unlock(&b);
unlock(&a);
}
void work_t2() {
ordered_lock(&b, &a);
// critical section using resources protected by a and b
unlock(&a);
unlock(&b);
}EL-GY 6483
(d) mutex_t a;
mutex_t b;
mutex_t wrapper;
void work_t1() {
lock(&wrapper);
lock(&a);
lock(&b);
unlock(&wrapper);
// critical section using resources
// protected by a and b
unlock(&b);
unlock(&a);
}
void work_t2() {
lock(&wrapper);
lock(&b);
lock(&a);
unlock(&wrapper);
// critical section using resources
// protected by a and b
unlock(&a);
unlock(&b);
}EL-GY 6483
2. Consider two tasks, τ1 and τ2, with descending priority (π1 > π2). These tasks have the following work
functions:
mutex_t a;
mutex_t b;
void work_t1() {
lock(&a);
// critical section using resource
// protected by a
lock(&b);
// critical section using resource
// protected by a and b
unlock(&b);
// critical section using resource
// protected by a
unlock(&a);
}
void work_t2() {
lock(&b);
// critical section using resource
// protected by b
lock(&a);
// critical section using resource
// protected by a and b
unlock(&a);
// critical section using resource
// protected by b
unlock(&b);
}
(a) Draw diagrams (like the ones at the end of the lecture slides) showing the priority inheritance
protocol and the priority ceiling promotion protocol, for the ordering where τ2 starts first, and is
preempted by τ1 in middle of executing its first critical section.
(b) Does the priority inheritance protocol protect against deadlock?
(c) Does priority ceiling promotion protect against deadlock?

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!