首页 > 编程语言 > 详细

Peterson算法

时间:2014-12-15 23:12:57      阅读:309      评论:0      收藏:0      [点我收藏+]
 1 #define FALSE 0
 2 #define TRUE 1
 3 #define N 2               /*进程数量 */
 4  
 5  int turn;                 /* 现在轮到谁 */
 6  int interested[N];            /*所有值初始化为0 (FALSE) */
 7  
 8  void enter_region(int process)    /*进程是0还是1 */
 9  {
10      int other;             /* 其他进程号*/
11      other = 1 - process;        /*另一方进程*/
12      interested[process] = TRUE;   /* 表明所感兴趣的 */
13      turn = process;          /* 设置标志 */
14      while(turn == process && interested[other] == TRUE);  /*空语句 */
15  }
16  
17  void leave_region(int process)    /*进程:谁离开*/
18  {
19      interested[[process] = FALSE; /* 表示离开临界区*/
20  }

 

Peterson算法

原文:http://www.cnblogs.com/lovejin/p/4165947.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!