Beispiel #1
0
 public void Reset()
 {
     if (Group.IsFirstThread)
     {
         Atomic.Exchange(ref address.Value, 0);
     }
 }
Beispiel #2
0
 private void Thread0()
 {
     flag0.Store(1, MemoryOrder);
     if (ActiveConfig.UseExchange)
     {
         victim.Exchange(0, MemoryOrder.AcquireRelease);
     }
     else
     {
         victim.Store(0, MemoryOrder);
     }
     while (flag1.Load(ActiveConfig.UseExchange ? MemoryOrder.Acquire : MemoryOrder) == 1 & victim.Load(MemoryOrder) == 0)
     {
         RE.Yield();
     }
     ++_threadsPassed;
     RE.Assert(_threadsPassed == 1, $"Mutual exclusion not achieved, {_threadsPassed} threads currently in critical section!");
     flag0.Store(0, ActiveConfig.UseExchange ? MemoryOrder.Release : MemoryOrder);
     --_threadsPassed;
 }
 public void SlowThread()
 {
     interestedS.Store(1, MemoryOrder.Relaxed);
     Fence.InsertProcessWide();
     victim.Exchange(1, MemoryOrder.AcquireRelease);
     while (true)
     {
         if (interestedF.Load(MemoryOrder.Relaxed) != 1)
         {
             break;
         }
         if (victim.Load(MemoryOrder.Relaxed) != 1)
         {
             break;
         }
         RE.Yield();
     }
     RE.Assert(_threadsPassed == 0, $"Slow thread entered while fast thread in critical section! ({_threadsPassed})");
     _threadsPassed++;
     interestedS.Store(0, MemoryOrder.Relaxed);
     _threadsPassed--;
 }