Documentation

Miri.Concurrency.Sync

Internal synchronization state from pinned Miri #

This file starts a source-shaped port of upstream/miri-source/src/concurrency/sync.rs (blob 3e848a071e2a67792eada4625b1751eec119b21d). It preserves the state fields of Mutex, RwLock, Condvar, Semaphore, and Futex. The lock transitions below preserve Miri's mutation order and use the existing GlobalState clock hooks and ThreadManager blocking/wakeup state.

Unblock callbacks are returned as explicit obligations. A transition carrying one has not completed the source operation yet. OS object lookup, shim-side memory checks, interpreter callback execution, futex/semaphore callback bodies, and actual memory writes remain outside this component; none is interpreted as success here. This is not a complete Rust concurrency semantics.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    The actual defaulted state held by Miri's Mutex.

    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        The actual defaulted state held by Miri's RwLock. Reader counts use a finite association list as a representation of the source FxHashMap; all operations preserve unique thread keys and positive counts.

        Instances For
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                Instances For
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    Instances For
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        Instances For
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Built-in callback bodies created by the generic sync layer. Pointer and scalar destinations are opaque interpreter tokens; this file never writes through them.

                            Instances For
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                Instances For
                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      structure Miri.Concurrency.SyncTransition (State Value : Type) (G : Type := GlobalState) :

                                      A callback request is a live, unresolved action in the source operation. outcome records the component's return value only as a continuation value; callers must run the request and use the corresponding completion function before treating the enclosing operation as returned.

                                      Instances For
                                        @[instance_reducible]
                                        instance Miri.Concurrency.instReprSyncTransition {State✝ Value✝ G✝ : Type} [Repr State✝] [Repr Value✝] [Repr G✝] :
                                        Repr (SyncTransition State✝ Value✝ G✝)
                                        Equations
                                        def Miri.Concurrency.instReprSyncTransition.repr {State✝ Value✝ G✝ : Type} [Repr State✝] [Repr Value✝] [Repr G✝] :
                                        SyncTransition State✝ Value✝ G✝ → Nat → Std.Format
                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          Instances For
                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For
                                              def Miri.Concurrency.SyncTransition.outcomeIsOk {State Value G : Type} (transition : SyncTransition State Value G) :
                                              Equations
                                              Instances For
                                                def Miri.Concurrency.SyncTransition.hasPendingWork {State Value G : Type} (transition : SyncTransition State Value G) :
                                                Equations
                                                Instances For

                                                  Mutation/check queuedResult before constructing a source blocking callback.

                                                  Instances For
                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For
                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For
                                                          Equations
                                                          Instances For
                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For
                                                              Equations
                                                              Instances For
                                                                def Miri.Concurrency.MutexState.lock {G : Type} [SyncClockState G] (state : MutexState) (global : G) (threads : ThreadManager) (handler : SyncClockHandler) (usizeBits : Nat := 64) :

                                                                Exact source operation mutex_lock: owner/count mutations precede acquire_clock, and therefore remain visible if that hook reports an error.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For
                                                                  def Miri.Concurrency.MutexState.enqueueAndBlock {G : Type} (state : MutexState) (global : G) (threads : ThreadManager) (callbackToken : Nat) :

                                                                  Exact source operation mutex_enqueue_and_block through block_thread. Queue insertion precedes the source assertion and blocking; the callback registration names the closure body installed by Miri.

                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For

                                                                    Exact source operation mutex_unlock. A woken thread is enabled and made active by unblockThread; the callback must then be completed with finishMutexAcquireCallback before the source operation has returned.

                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For
                                                                      def Miri.Concurrency.finishMutexAcquireCallback {G : Type} [SyncClockState G] (state : MutexState) (global : G) (threadsAfterUnblock : ThreadManager) (request : SyncCallbackRequest) (handler : SyncClockHandler) (unlockResult : MutexUnlockResult) (usizeBits : Nat := 64) :

                                                                      Execute the known internal callback installed by mutex_enqueue_and_block: it requires a Ready unblock, asserts that ownership was transferred to an unlocked mutex, acquires the lock/clock, and restores the previously active thread only after normal callback return.

                                                                      Equations
                                                                      • One or more equations did not get rendered due to their size.
                                                                      Instances For

                                                                        Continuation used by condvar_reacquire_mutex when the mutex is still owned. It runs Miri's installed callback through lock/clock acquisition, then leaves the captured scalar store as an explicit interpreter obligation.

                                                                        Equations
                                                                        • One or more equations did not get rendered due to their size.
                                                                        Instances For
                                                                          Equations
                                                                          Instances For
                                                                            def Miri.Concurrency.RwLockState.readerLock {G : Type} [SyncClockState G] (state : RwLockState) (global : G) (threads : ThreadManager) (handler : SyncClockHandler) (usizeBits : Nat := 64) :

                                                                            Exact rwlock_reader_lock state update and following clock acquire.

                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For

                                                                              Exact rwlock_writer_lock state update and following clock acquire.

                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.
                                                                              Instances For
                                                                                def Miri.Concurrency.RwLockState.enqueueReaderAndBlock {G : Type} (state : RwLockState) (global : G) (threads : ThreadManager) (callbackToken returnValueToken destinationToken : Nat) :

                                                                                Queue a reader behind a writer, preserving the source's push-before-assert and block_thread order. The closure's scalar write is an opaque token.

                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For
                                                                                  def Miri.Concurrency.RwLockState.enqueueWriterAndBlock {G : Type} (state : RwLockState) (global : G) (threads : ThreadManager) (callbackToken returnValueToken destinationToken : Nat) :

                                                                                  Queue a writer behind an existing reader or writer, using the source's writer queue and callback registration.

                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For

                                                                                    Exact rwlock_reader_unlock ordering. It first removes/decrements the reader entry, then releases and joins the active clock, then transfers the joined-reader clock and wakes one queued writer if the lock becomes free.

                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For

                                                                                      Exact rwlock_writer_unlock: the writer clears ownership before the clock release; queued writers have priority, otherwise all waiting readers are removed from the queue before their callbacks are invoked in FIFO order.

                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For
                                                                                        def Miri.Concurrency.RwLockState.continueReaderWakeups {G : Type} (state : RwLockState) (global : G) (threadsAfterCallback : ThreadManager) (request : SyncCallbackRequest) (returnedNormally : Bool) (callbackRegistry : List (Nat × SyncCallbackProgram) := []) :

                                                                                        Continue a source loop that is waking the readers drained by rwlock_writer_unlock. The caller must first execute the callback in the previous request and provide its resulting manager.

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For

                                                                                          Run the internal callback body installed while a reader/writer waited for an RwLock: acquire the appropriate lock/clock, then expose the source's write_scalar as a pending interpreter action.

                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For
                                                                                            def Miri.Concurrency.CondvarState.blockAfterMutexUnlock {G : Type} (state : CondvarState) (global : G) (threads : ThreadManager) (unlockResult : MutexUnlockResult) (deadline : Option ThreadDeadline) (callbackToken mutexToken successValueToken timeoutValueToken destinationToken : Nat) (communicate : Bool) :

                                                                                            Continue condvar_wait only after mutex_unlock returned successfully with an original count of one. The call preserves the source order: waiter queue insertion, then checked blocking with its timeout constraints.

                                                                                            Equations
                                                                                            • One or more equations did not get rendered due to their size.
                                                                                            Instances For

                                                                                              Exact condvar_signal: release the signal clock before popping a waiter, then unblock at most the FIFO head. The callback stays pending until the interpreter executes the captured condvar/mutex continuation.

                                                                                              Equations
                                                                                              • One or more equations did not get rendered due to their size.
                                                                                              Instances For
                                                                                                def Miri.Concurrency.CondvarState.finishWaitCallback {G : Type} [SyncClockState G] (state : CondvarState) (mutex : MutexState) (global : G) (threadsAfterUnblock : ThreadManager) (request : SyncCallbackRequest) (handler : SyncClockHandler) (mutexToken newMutexCallbackToken : Nat) :

                                                                                                Execute the internal condvar callback through its source effects. On Ready it acquires the signal clock; on timeout it first removes the waiter. It then reacquires the captured mutex. If another thread owns it, this thread blocks on that mutex with the source lock-and-write callback registered. If the mutex is free, it acquires it and leaves the captured scalar write pending.

                                                                                                Equations
                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                Instances For
                                                                                                  def Miri.Concurrency.FutexState.wait {G : Type} (state : FutexState) (global : G) (threads : ThreadManager) (bitset : UInt32) (deadline : Option ThreadDeadline) (callbackToken userCallbackToken : Nat) (communicate : Bool) :

                                                                                                  Exact source futex_wait registration: reject a duplicate waiter, append the thread/bitset pair, then apply Miri's timeout checks and block it. Its callback wrapper is retained as an explicit registration for the wake path.

                                                                                                  Equations
                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                  Instances For
                                                                                                    def Miri.Concurrency.FutexState.wake {G : Type} [SyncClockState G] (state : FutexState) (global : G) (threads : ThreadManager) (bitset : UInt32) (count : Nat) (handler : SyncClockHandler) (callbackRegistry : List (Nat × SyncCallbackProgram) := []) :

                                                                                                    Exact futex_wake: release the clock before filtering and removing waiters; the first unblock callback and every continuation are returned explicitly.

                                                                                                    Equations
                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                    Instances For

                                                                                                      Miri's futex wrapper acquires the futex clock on Ready, removes the active waiter on timeout, then invokes the OS-shim callback. That last callback is opaque here and remains pending until the caller supplies its actual result.

                                                                                                      Equations
                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                      Instances For
                                                                                                        def Miri.Concurrency.FutexState.continueWake {G : Type} (state : FutexState) (global : G) (threadsAfterCallback : ThreadManager) (request : SyncCallbackRequest) (wokenCount : Nat) (returnedNormally : Bool) (callbackRegistry : List (Nat × SyncCallbackProgram) := []) :

                                                                                                        Continue the futex_wake source loop only after the previous outer and OS-shim callbacks returned normally. Callback failure stops the loop before active-thread restoration, as Miri's ? propagation does.

                                                                                                        Equations
                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                        Instances For
                                                                                                          def Miri.Concurrency.finishScalarWriteCallback {G State : Type} (state : State) (global : G) (threadsAfterWrite : ThreadManager) (request : SyncCallbackRequest) (writeSucceeded : Bool) :

                                                                                                          Complete the actual interpreter write_scalar hook at the end of a mutex/rwlock/condvar unblock callback. A failed write preserves the callback's state and active-thread context, matching source ? propagation.

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          Instances For
                                                                                                            def Miri.Concurrency.finishOpaqueSyncCallback {G State : Type} (syncState : State) (global : G) (threadsAfterCallback : ThreadManager) (request : SyncCallbackRequest) (returnedNormally : Bool) :

                                                                                                            Complete a callback body whose implementation belongs to an OS shim or the interpreter. The caller supplies the post-callback manager and the actual return status; errors preserve its active-thread state, while normal return restores the previous active thread exactly once.

                                                                                                            Equations
                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                            Instances For
                                                                                                              def Miri.Concurrency.SemaphoreState.decrement {G : Type} [SyncClockState G] (state : SemaphoreState) (global : G) (threads : ThreadManager) (deadline : Option ThreadDeadline) (blockCallbackToken userCallbackToken : Nat) (handler : SyncClockHandler) (communicate : Bool) :

                                                                                                              Exact source semaphore decrement through value update, clock acquire, and callback registration. If the counter is zero, queue insertion precedes checked blocking and the callback remains attached to the thread.

                                                                                                              Equations
                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                              Instances For
                                                                                                                Equations
                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                Instances For