Using Interlocked.Exchange(ref Enum, 1) to prevent re-entrancy [migrated]
- by makerofthings7
What options do I have for pending work that can't acquire a lock via the following sample?
System.Threading.Interlocked.CompareExchange<TrustPointStatusEnum>
(ref tp.TrustPointStatus, TrustPointStatusEnum.NotInitalized,TrustPointStatusEnum.Loading);
Based on my research think I have the following options:
I can use Threading.SpinWait (for very quick IO tasks) at the cost of CPU
I can use Sleep() which has an unreliable wake up time
I'm not sure of any other option, but what I want to make sure of is that all these options work with the .NET 4 async and await keywords, especially if I use Task to run them on a background thread