示例#1
0
 bool endOfRoad(int pos_X, int pos_Y, Road road)
 {
     if (pos_X >= 24 || pos_Y >= 24 || pos_X <= 0 || pos_Y <= 0)
     {
         road.GetRoadMutex(pos_X, pos_Y).WaitOne();
         road.setSpaceFree(pos_X, pos_Y);
         road.GetRoadMutex(pos_X, pos_Y).ReleaseMutex();
         return(true);
     }
     return(false);
 }
示例#2
0
 bool singleMove()
 {
     step();
     road.GetRoadMutex(next_pos_X, next_pos_Y).WaitOne();
     if (road.checkSpace(next_pos_X, next_pos_Y))
     {
         //you can go into next_pos
         //zajmij miejsce ,zmien miejsce, zwolnij stare miejsce
         road.setSpaceOccupied(next_pos_X, next_pos_Y);
         old_pos_X  = pos_X;
         old_pos_Y  = pos_Y;
         pos_X      = next_pos_X;
         pos_Y      = next_pos_Y;
         shouldFree = true;
     }
     else
     {
         shouldFree = false;
     }
     road.GetRoadMutex(next_pos_X, next_pos_Y).ReleaseMutex();
     //avoiding nested mutex lock!!!
     if (shouldFree)
     {//
         road.GetRoadMutex(old_pos_X, old_pos_Y).WaitOne();
         road.setSpaceFree(old_pos_X, old_pos_Y);
         road.GetRoadMutex(old_pos_X, old_pos_Y).ReleaseMutex();
         if (pos_X == 13 && pos_Y == 11)
         {
             unlockYourLane(road);
         }
         if (pos_X == 14 && pos_Y == 13)
         {
             unlockYourLane(road);
         }
         if (pos_X == 11 && pos_Y == 12)
         {
             unlockYourLane(road);
         }
         if (pos_X == 12 && pos_Y == 14)
         {
             unlockYourLane(road);
         }
         return(true);
     }
     return(false);
 }