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 }
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; }
public void Unlock() { int i = ThreadID.Get(); flag[i] = false; // I’m not interested }