ddn.concurrent.thunk

Thread-safe, synchronous, memoized lazy initialization.

SharedThunk copies share one computation. The first forcing caller evaluates its recipe on its own thread; other callers wait for that outcome. There is no worker pool, scheduling, retry, invalidation or cancellation. Same-thread recursion is detected; cross-thread dependency cycles remain the application's responsibility. All participating threads must use druntime.

Recipes are @safe function pointers with explicitly supplied, shareable arguments, not captured delegates. Values and arguments must have no unshared mutable aliases or custom copy/assignment/destruction hooks. Explicitly shared referenced data still needs its own synchronization.

Recoverable failures are published as immutable diagnostics. force() throws a fresh SharedThunkException, never a shared mutable exception object; tryForce() uses existing DDN result types. Errors are not converted to recoverable results. See doc/CONCURRENT-THUNK.md for the full contract.

Types 3

Recoverable diagnostic returned by a shared thunk's tryForce().

The type parameter distinguishes the error role from every supported success payload. Strings reference immutable characters; each returned record has its own bindings. No original exception, cause chain or traceback is shared.

Parameters

TSuccess type, or void.
Fields
string exceptionTypeOriginal exception class name.
string messageOriginal exception message.
string fileOriginal exception's source file.
size_t lineOriginal exception's source line.
classSharedThunkException : Exception

Fresh, caller-owned exception representing a cached recoverable failure.

Fields
string exceptionTypeOriginal exception class name, not the name of this adapter.
Constructors
this(string exceptionType, string message, string file, size_t line)Construct a caller-owned exception from immutable diagnostic fields. Params: exceptionType = Original exception class name. message = Original exception message. file = Original source file. line =...
structSharedThunk(T)

Copyable handle to thread-safe, synchronous, one-time lazy initialization.

Construction and rebinding are ordinary owner operations: do not concurrently rebind/move the same handle storage. Concurrent forcing of initialized copied handles or shared fields is supported. Const/immutable handles cannot force.

Every force consults the state mutex; there is no unchecked fast path. Same thread recursion throws ddn.thunk.ThunkCycleError; callers must prevent cyclic cross-thread waits. Blocking is for OS threads, not fibre scheduling.

Parameters

TShareable plain payload type, or void.
Methods
T force(this This)() if (!is(This == const) && !is(This == immutable)) @safeForce initialization or wait for another thread's published outcome. Returns: A payload copy, or nothing for `void`. Throws: `InvalidThunkException` for an empty handle; a fresh SharedThunkExceptio...
T opCall(this This)() if (!is(This == const) && !is(This == immutable)) @safeExplicit call shorthand for forcing. Returns: The same payload copy as `force()`, or nothing for `void`. Throws: The same failures as `force()`.
SharedThunkResult!T tryForce(this This)() if (!is(This == const) && !is(This == immutable)) @safeForce and report recoverable failures using DDN result types.
Constructors
this(T function(A) @safe recipe, A arguments)Construct pending initialization without invoking the function. Params: recipe = Non-null safe function pointer; captured delegates are rejected. arguments = Shareable plain argument bindings, reta...

Functions 1

fnSharedThunk!T sharedThunk(T, A...)(T function(A) @safe recipe, A arguments) @safeInfer a shared thunk's payload from a noncapturing safe function. Params: recipe = Non-null safe function pointer, not a captured delegate. arguments = Already evaluated shareable bindings; the rec...

Templates 2

tmplSharedThunkResult(T)

Recoverable outcome of a shared forcing attempt.

Parameters

TSuccess type, or void for Status.
tmplcontainsContext(T, Seen...)

Detect hidden lexical contexts in copied values and known element types.

hasUnsharedAliasing alone can miss a nested struct's implicit frame pointer. Inspect value fields and element types explicitly, with a visited-type set for recursive pointer representations. Class references are boundaries: check their declared type's own context, not implementation fields of an explicitly shared/immutable object, whose synchronization/validity remains its contract.

Parameters

TType to inspect without constructing a value.
SeenTypes already visited along the current representation path.