美文网首页
讲解:EL-GY 6483、c/c++,Java、PythonP

讲解:EL-GY 6483、c/c++,Java、PythonP

作者: bingernai | 来源:发表于2020-01-10 12:50 被阅读0次

EL-GY 6483Scheduling 21. Suppose the functions work_t1(), work_t2(), and work_t3() are called from different threads. Whichof the examples below could potentially lead to deadlock of these threads? For each code sample thatmay 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 bunlock(&b);unlock(&a);}void work_t2() {lock(&a);// critical section using resources// protected by aunlock(&a);}void work_t3() {lock(&b);// critical section using resources// protected by bunlock(&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 bunlock(&b);unlock(&a);}void work_t2() {lock(&b);lock(&a);// critical section using resources// protected by a and bunlock(&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 orderif (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 bunlock(&b);unlock(&a);}void work_t2() {ordered_lock(&b, &a);// critical section using resources protected by a and bunlock(&a);unlEL-GY 6483作业代做、c/c++,Java编程语言作业代写、代做Python实验作业 代写留学生Prolog|代ock(&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 bunlock(&b);unlock(&a);}void work_t2() {lock(&wrapper);lock(&b);lock(&a);unlock(&wrapper);// critical section using resources// protected by a and bunlock(&a);unlock(&b);}EL-GY 64832. Consider two tasks, τ1 and τ2, with descending priority (π1 > π2). These tasks have the following workfunctions:mutex_t a;mutex_t b;void work_t1() {lock(&a);// critical section using resource// protected by alock(&b);// critical section using resource// protected by a and bunlock(&b);// critical section using resource// protected by aunlock(&a);}void work_t2() {lock(&b);// critical section using resource// protected by block(&a);// critical section using resource// protected by a and bunlock(&a);// critical section using resource// protected by bunlock(&b);}(a) Draw diagrams (like the ones at the end of the lecture slides) showing the priority inheritanceprotocol and the priority ceiling promotion protocol, for the ordering where τ2 starts first, and ispreempted 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?转自:http://www.7daixie.com/2019052140782405.html

相关文章

网友评论

      本文标题:讲解:EL-GY 6483、c/c++,Java、PythonP

      本文链接:https://www.haomeiwen.com/subject/bevpactx.html