@@ -67,6 +67,67 @@ catch (InvalidOperationException ex)
6767 Console .WriteLine (" Transaction failed: " + ex .Message );
6868}
6969```
70+ ## 📦 Core Classes
71+
72+ ### ` ISTMVariable<T> ` (interface)
73+ Represents a shared STM variable within the system.
74+
75+ | Member | Description |
76+ | --------| -------------|
77+ | ` ReadWithVersion() ` | Atomically reads the value and version. |
78+ | ` Write(T value) ` | Atomically writes a new value. |
79+ | ` int Version { get; } ` | Gets the current version of the variable. |
80+ | ` IncrementVersion() ` | Increments the version manually. |
81+
82+ > ⚠️ Intended for internal STM operations only, not exposed to user code directly.
83+
84+ ---
85+
86+ ### ` STMVariable<T> ` : ` ISTMVariable<T> `
87+ Concrete implementation of a ** thread-safe STM variable** using ` Volatile ` and ` Interlocked ` .
88+
89+ | Field/Method | Description |
90+ | --------------| -------------|
91+ | ` _boxedValue ` | Internal boxed value to support both value and reference types. |
92+ | ` Read() ` | Simple thread-safe read. |
93+ | ` Write(T value) ` | Writes the new value and increments the version. |
94+ | ` ReadWithVersion() ` | Returns a consistent snapshot of value and version. |
95+ | ` Version ` / ` IncrementVersion() ` | Handles versioning for conflict detection. |
96+
97+ > ✅ Used as the shared state managed inside transactions.
98+
99+ ---
100+
101+ ### ` Transaction<T> `
102+ Represents an atomic unit of work. Implements ** pessimistic isolation** and conflict detection via version locking.
103+
104+ | Field | Description |
105+ | -------| -------------|
106+ | ` _reads ` | Cache of read values. |
107+ | ` _writes ` | Pending writes to apply at commit time. |
108+ | ` _lockedVersions ` | Versions locked during reads to check for conflicts. |
109+ | ` Read(...) ` | Reads from STM variable and locks its version. |
110+ | ` Write(...) ` | Records an intended write to apply later. |
111+ | ` CheckForConflicts() ` | Verifies if any STM variable has changed since read. |
112+ | ` Commit() ` | Applies writes if no conflicts are detected. |
113+ | ` ConflictCount ` / ` RetryCount ` | Static counters for diagnostics. |
114+
115+ > ♻️ A new transaction is created on each attempt (controlled by ` STMEngine ` ).
116+
117+ ---
118+
119+ ### ` STMEngine `
120+ Coordinates STM execution with ** retry and exponential backoff** strategy.
121+
122+ | Method | Description |
123+ | --------| -------------|
124+ | ` Atomic<T>(Action<Transaction<T>>) ` | Runs a synchronous transactional block. |
125+ | ` Atomic<T>(Func<Transaction<T>, Task>) ` | Runs an async transactional block. |
126+ | ` DefaultMaxAttempts ` / ` DefaultInitialBackoffMilliseconds ` | Default retry/backoff configuration. |
127+
128+ > 🔁 Retries the transaction on conflict, doubling delay after each failure.
129+
130+ ---
70131
71132## Benchmarking
72133This project includes a benchmarking application designed to test and simulate the behavior of the STMSharp library under varying conditions. The benchmark is built to analyze the efficiency and robustness of the STM mechanism. The benchmark parameters are configurable through a JSON file named appsettings.json. This allows centralized and flexible management of the values used for testing.
0 commit comments