Custom attribute that, when applied to a class, applies the ReaderWriterSynchronizedThreadingModel model to this class and all derived classes. Members of this class must then be annotated with attributes specifying the required access level (ReaderAttribute, WriterAttribute, YielderAttribute or UpgradeableReaderAttribute), otherwise build-time and run-time errors are emitted.
Inheritance
Implements
Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.ReaderWriterSynchronized")]
[Serializer(typeof(ReaderWriterSynchronizedAttribute.Serializer))]
public sealed class ReaderWriterSynchronizedAttribute : ThreadAwareAttribute, ITypeLevelAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ICloneAwareAspect, IInstanceScopedAspect, IAspectProvider, IService, IAdviceProvider, IAspect, IThreadAware, IQueryInterfaceRemarks
Several threads can execute reader methods of the same object concurrently, but a writer method has exclusive access to the object. Annotate public and internal methods with an access-level attribute; a warning is emitted at build time for a method that has none. Public and internal property getters and setters do not need an attribute because they require read and write access respectively, and event accessors do not need one either.
A build-time error is emitted when the class has public or internal fields, or when an async method is not annotated
with the ReentrantAttribute custom attribute. When run-time verification is enabled, accessing a field without the required
access level, for instance writing a field from a reader method, results in a ThreadAccessException.
When the object becomes a child of an object that has the SynchronizedAttribute aspect, it shares the lock of its parent, and all its methods then require exclusive access.
Constructors
| Name | Description |
|---|---|
| ReaderWriterSynchronizedAttribute() | |
| ReaderWriterSynchronizedAttribute(PortableFormatterConstructorContext) |