CSharp - Using SpinLocks

From PeformIQ Upgrade
Revision as of 11:40, 16 March 2014 by 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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