コード例 #1
0
        public void Lock()
        {
            int i = ThreadID.Get();
            int j = 1 - i;

            flag[i] = true; // I’m interested
            victim  = i;    // you go first
            while (flag[j] && victim == i)
            {
            }
            ;                                   // wait
        }
コード例 #2
0
        public void Lock()
        {
            int i = ThreadID.Get();

            flags[i]        = true;
            labels[i].Value = labels.Max(x => x.Value) + 1;

            while (labels.Select((label, index) =>

                                 (index != i) &&
                                 flags[index] &&
                                 ((labels[index].Value < labels[i].Value) ||
                                  (labels[index].Value == labels[i].Value) &&
                                  index < i))

                   .Aggregate(false, (x, y) => x || y))
            {
            }
            ;
        }
        public void Lock()
        {
            int i = ThreadID.Get();

            flags[i]  = true;
            labels[i] = labels.Max() + 1;

            while (labels.Select((label, index) =>

                                 (index != i) &&
                                 flags[index] &&
                                 (
                                     (labels[index] < labels[i]) ||
                                     ((labels[index] == labels[i]) && index < i))
                                 )

                   .Any(x => x))
            {
            }
            ;
        }
 public void Unlock()
 {
     flags[ThreadID.Get()] = false;
 }
コード例 #5
0
        public void Unlock()
        {
            int i = ThreadID.Get();

            flag[i] = false; // I’m not interested
        }