Difference between revisions of "CSharp - Using SpinLocks"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (Created page with "=Example= From - http://stackoverflow.com/questions/15164408/lock-free-concurrent-queue This code snippet is from ConcurrentQueue implementation. <pre> internal bool TryPee...") |
PeterHarding (talk | contribs) |
||
Line 19: | Line 19: | ||
result = m_array[lowLocal]; | result = m_array[lowLocal]; | ||
return true; | return true; | ||
} | |||
</pre> | </pre> | ||
Latest revision as of 11:40, 16 March 2014
Example
From - http://stackoverflow.com/questions/15164408/lock-free-concurrent-queue
This code snippet is from ConcurrentQueue implementation.
internal bool TryPeek(out T result) { result = default(T); int lowLocal = Low; if (lowLocal > High) return false; SpinWait spin = new SpinWait(); while (m_state[lowLocal] == 0) { spin.SpinOnce(); } result = m_array[lowLocal]; return true; }
Also see - http://msdn.microsoft.com/en-us/library/hh228603.aspx