|
|
|
|
|
|
z****e 发帖数: 2024 | 1 请问如下这个问题是怎么解决的?
看不懂。用mutex好像不行。也不知道semaphore怎么工作的。
Suppose we have the following code to use class Foo. We do not know how the threads will be scheduled in the OS.
question:
Can you design a mechanism to make sure that all the methods will be executed in sequence?
Foo f;
f.A(.....);
f.B(.....);
f.C(.....);
f.A(.....);
f.B(.....);
f.C(.....);
solution:
Semaphore s_a(0);
Semaphore s_b(0);
Semaphore s_c(1);
A {
s_c.acqure(1);
/***/
s_a.release(1);
}
B {
s_a.acqure(1);
/****/
s_b.release(1);
}
C {
s | y***d 发帖数: 2330 | 2 what is the question of the ultima answer?
the
【在 z****e 的大作中提到】 : 请问如下这个问题是怎么解决的? : 看不懂。用mutex好像不行。也不知道semaphore怎么工作的。 : Suppose we have the following code to use class Foo. We do not know how the threads will be scheduled in the OS. : question: : Can you design a mechanism to make sure that all the methods will be executed in sequence? : Foo f; : f.A(.....); : f.B(.....); : f.C(.....); : f.A(.....);
| z****e 发帖数: 2024 | 3 不好意思,题没贴全,补上了,就是按照那几个函数call的顺序call。
【在 y***d 的大作中提到】 : what is the question of the ultima answer? : : the
|
|
|
|
|
|