void LockfreeUpdate(ref double volatileUpdateTarget, double value) { SpinWait sw = new SpinWait(); while (true) { // after this line, other thread can update the ref double, double comparandAsSnapshot = volatileUpdateTarget; //w/o barrier, before instruction changing volatileUpdateTarget move to after Snapshot=> comparandAsSnapshot stale=>extra spin Thread.MemoryBarrier(); // if preempted=>updateTarget changed != comparand=> no copy, and spin. double? originalRefValueBeforeExchComp = Interlocked.CompareExchange(ref volatileUpdateTarget, value, comparandAsSnapshot); if (originalRefValueBeforeExchComp == comparandAsSnapshot) return; // no preemption sw.SpinOnce(); } } void LockfreeUpdate<T>(ref T volatileUpdateTarget,T value) where T: class { SpinWait sw = new SpinWait(); while (true) { // after this line, other thread can update the ref double, T comparandAsSnapshot = volatileUpdateTarget; // ICE has internal MemoryBarrier so just extra spin here // if preempted=>updateTarget changed != comparand=> no copy, and spin. T originalRefValueBeforeExchComp = Interlocked.CompareExchange(ref volatileUpdateTarget, value, comparandAsSnapshot); if (originalRefValueBeforeExchComp == comparandAsSnapshot) return; // no preemption sw.SpinOnce(); } } void LockfreeUpdate<T>(ref T volatileUpdateTarget,func<T,T> updateFunc) where T: class { SpinWait sw = new SpinWait(); while (true) { // after this line, other thread can update the ref double, T comparandAsSnapshot = volatileUpdateTarget; // if preempted=>updateTarget changed != comparand=> no copy, and spin. T originalRefValueBeforeExchComp = Interlocked.CompareExchange(ref volatileUpdateTarget, updateFunc(comparandAsSnapshot ), comparandAsSnapshot); if (originalRefValueBeforeExchComp == comparandAsSnapshot) return; // no preemption sw.SpinOnce(); } }
Saturday, August 29, 2015
Lock Free Volatile Field Updates
Subscribe to:
Post Comments (Atom)
2 comments:
When the sadness is surging in the chest, the warm will come in time, and ease the pain in your heart. This is life.
_________________________
I find a funny game,let'go!
But I even have this higher, you'll take a look: rsgoldfast and rsgoldfast.com
سايت جامع املاک تبريز
املاک وليعصرتبريز
املاک ائل گلي تبريز
کانال تلگرام املاک تبريز
املاک تبريز118
ملک تبريز
جستجوي ملک روي نقشه تبريز
دانلود قالب وردپرس
دانلود قالب فروشگاهي وردپرس
دانلود رايگان قالب وردپرس
دانلود افزونه وردپرس
Post a Comment