首页 > 试题广场 >

Describe how the Swap( ) instr

[问答题]
Describe how the Swap( ) instruction can be used to provide mutual exclusion that satisfies the bounded-waiting requirement.
推荐
do {
      waiting [ i ] = TRUE;
      key = TRUE;
      while (waiting [ i ] && key)
             key = Swap (&lock, &key);
    
      waiting [ i ] = FALSE;
        
      / * critical section * /
      j = (i+1) % n;
     while ((j!=i) && !waiting [ j ])
            j=(j+1) % n;
     if (j == i)
            lock = FALSE;
     else
            waiting [ j ] = FALSE;
     / * remainder section * /
} while (TRUE);

发表于 2018-03-18 21:56:22 回复(0)