memory::Owner
The sole owner + scheduling coordinator for one T.
Non-copyable and pinned, so the object never moves; every access goes through a request → acquire → lease.
T | the owned type. |
Functions
Owner · 3 overloads
Take sole ownership by MOVING value in — the object is consumed (its resources move into the Owner), never copied.
An lvalue won't bind here (bind an rvalue: own(std::move(x))).
value | the object to take ownership of (moved in). |
pol | the scheduling policy (interleave / writes_first). |
O(1) plus moving value.
one read-generation gate (std::make_shared); the value's own storage just moves.
construct before sharing; the pinned Owner must outlive every lease and every thread that uses it.
operator= · 2 overloads
Request a shared READ lease.
Blocks — in THIS call: the grant is synchronous, so the returned request is already fulfilled — only while a write is pending/active or queued; otherwise many read leases coexist.
a request for a read lease.
O(1) amortized.
the request's promise/future.
callable from any thread; readers share. Writer-preference: this waits while any write is active, suspended, or queued, so writers cannot starve.
requesting while the SAME thread still holds a lease on this owner can deadlock (a queued write makes the grant wait on that very lease) — renewal is release, then re-request.
MemoryCheatah.ReadLeaseValidStateRequest an exclusive WRITE lease at compile-time priority (a plain int or the caller's enum; higher = served first, ties FIFO).
priority < 0 (spell it memory::immediate) is an immediate-write. Blocks in THIS call — the grant is synchronous, so the returned request is already fulfilled — until the readers drain and this write wins the queue.
priority | the compile-time write priority. |
a request for a write lease.
O(log k) to enqueue among k waiters (O(1) immediate), plus the blocking wait.
the request's promise/future, two fresh gates (std::make_shared: this write's own + the next read generation's), plus one queue-ticket slot (amortized) for a non-immediate write.
callable from any thread. Drain-before-write: flips the current read generation's gate and waits until every reader has released and no other write is active; an immediate-write skips the queue and additionally preempts a cooperating active writer (which resumes after).
requesting while the SAME thread still holds a lease on this owner deadlocks (the drain waits on that very lease) — release first, then re-request.
Memory.WriteWaitsForReadersToDrain Memory.HigherPriorityWriteServedFirst Memory.NegativePriorityImmediateWritePreemptsTheActiveWriterWhichThenResumes MemoryConcurrency.ManyWritersDeterministicSumMemoryCheatah.ConcurrentSumOverSharedOwnerConstants & variables
active read leases.
an active (non-suspended) write lease.
active writer paused for an immediate-write.
an immediate-write holds exclusive access.
current read generation's yield gate.
the active writer's gate (for preempt/resume).
waiting non-immediate writes.
