作为我的任务,我必须验证Dekker的算法 - 但有3个过程 -
我只能找到2个进程的原始版本。
目标不是算法,而是SMV系统中的实现和验证 http://www.cs.cmu.edu/~modelcheck/smv.html
答案 0 :(得分:3)
您可能应该问课程人员,但您可以使用两个Dekker互斥锁来实现三进程互斥锁。进程0和1竞争获取互斥锁A;互斥锁A和进程2的持有者竞争获取互斥锁B,允许其持有者运行关键部分。
答案 1 :(得分:1)
// Dekkers algorithm version3
system:
boolean t1WantsToEnter=false;
boolean t2WantsToEnter=false;
startThreads;//initialize and launch all threads
Thread T1;
void main();{
while(!done);
{
t1WantsToEnter=true;
while(t2WantsToEnter); //wait
//critical section cokde
t1WantsToEnter=false;
//code outside critical section
Thread T2;
void main();{
while(!done);
{
t2WantsToEnter=true;
while(t1WantsToEter);//wait
//critical section code
t2WantsToEnter=false;
//code outside critical section
// if u want to know how this code is executed using RAM diagram,
答案 2 :(得分:0)
// Dekkers algorithm version3
system:
boolean t1WantsToEnter=false;
boolean t2WantsToEnter=false;
startThreads;//initialize and launch all threads
Thread T1;
void main();{
while(!done);
{
t1WantsToEnter=true;
while(t2WantsToEnter); //wait
//critical section cokde
t1WantsToEnter=false;
//code outside critical section
} //end outer while
} //end Thread T1
Thread T2;
void main();{
while(!done);
{
t2WantsToEnter=true;
while(t1WantsToEter);//wait
//critical section code
t2WantsToEnter=false;
//code outside critical section
} //end outer while
} //end Thread T2