Пример #1
0
 public void Add(int v)
 {
     while (true)
     {
         var local = RVolatile.Read(ref _data);
         var copy  = local == null ? new List <int>() : new List <int>(local);
         copy.Add(v);
         if (RInterlocked.CompareExchange(ref _data, copy, local))
         {
             break;
         }
     }
 }
Пример #2
0
            internal LockCookie Enter()
            {
                int currentThreadId = Environment.CurrentManagedThreadId;

                LockCookie entry = RUnordered.Read(ref _current);

                if (entry?.ThreadId == currentThreadId)
                {
                    RUnordered.Write(ref entry.Taken, 1);

                    if (RVolatile.Read(ref _current) == entry)
                    {
                        return(entry);
                    }
                    RUnordered.Write(ref entry.Taken, 0);
                }
                return(EnterSlow());
            }