联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2019-05-20 11:22

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?


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp