namespace System.Threading;
/// A value many threads read at once or one writes (Rust's `RwLock`, .NET's
/// `ReaderWriterLockSlim`).
[Intrinsic]
[Threads(ThreadSafety.Guarded)]
public readonly sealed class ReadWriteLock<T> {
public ReadWriteLock(T value) {}
public readonly ReadGuard<T> Read();
public readonly WriteGuard<T> Write();
public readonly ReadGuard<T>? TryRead();
public readonly WriteGuard<T>? TryWrite();
}
/// A read of a `ReadWriteLock`, until it's dropped.
[Intrinsic]
[Threads(ThreadSafety.Bound)]
public sealed class ReadGuard<T> : IDisposable {
public T Value { get; }
public void Dispose();
}
/// A write of a `ReadWriteLock`, until it's dropped.
[Intrinsic]
[Threads(ThreadSafety.Bound)]
public sealed class WriteGuard<T> : IDisposable {
public T Value { get; set; }
public void Dispose();
}