Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace Core.Threading {
- /// <summary>
- /// Used to synchronize access to a single-use consumable resource
- /// </summary>
- public sealed class SingleEntryGate {
- private const int NOT_ENTERED = 0;
- private const int ENTERED = 1;
- private int _status;
- /// <summary>
- /// Returns true if this is the first call to TryEnter(), false otherwise
- /// </summary>
- public bool TryEnter() {
- int oldStatus = Interlocked.Exchange(ref _status, ENTERED);
- return (oldStatus == NOT_ENTERED);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment