测试和设置指令如何满足(或不满足)关键部分方法的条件 [英] How test-and-set instruction satisfies (or does not satisfy) conditions for critical section approach

查看:234
本文介绍了测试和设置指令如何满足(或不满足)关键部分方法的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看流程同步,并遇到了测试设置指令

I was looking at process synchronization and came across test-and-set instruction

boolean testAndSet (boolean *target)
{  
     boolean rv = *target;
     *target = true;
     return rv;
}

main()
{
      do
      {
          while( testAndSet( &lock ));

          //critical section
          lock = false;

          //remainder section
       }while(true);

 }

这是原子执行的(即,每当对testAndSet的函数调用发生时,直到函数返回之前都不会处理任何中断).

This executes atomically (i.e. whenever a function call to testAndSet occurs no interrupt is handled till the function returns).

现在,我了解了如何消除相互排斥(因为如果另一个进程正在执行,则等待的进程将卡在while循环中,这是关键部分).但是,它如何满足Progress条件,更重要的是,它如何不满足bound-buffer条件?任何帮助将不胜感激..

Now I understand how this eliminates mutual exclusion (since the waiting process gets stuck at the while loop if another process is executing it's critical section). But how does it satisfy Progress condition, and more importantly, how does it not satisfy bounded-buffer condition? Any help would be appreciated..

推荐答案

为了取得进展,可以说,PO在关键部分,P1,P2和P3在等待. PO离开后,立即将lock设置为false,然后下一个进程退出while条件并进入临界区. 对于有限的等待,我不确定,但是如果说,具有较高优先级的P4出现并反复请求进入关键部分.然后,P1,P2,P3将永远没有机会进入该区域.因此,他们将无限等待.

For progress lets say, PO is in the critical section and P1,P2 and P3 are waiting. As soon as PO leaves, it sets lock to false and just after that the next process exits the while condition and enters the critical section. For bounded waiting, I am not sure of but if lets say, P4 with a high priority comes and repeatedly requests to enter the critical section. Then, P1,P2,P3 will never get the chance to enter the section. Hence, they'll wait infinitely.

这篇关于测试和设置指令如何满足(或不满足)关键部分方法的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆