Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Struct

Status

Private Struct
std.Io.Threaded.Thread.Status
const Status = packed struct(usize)

Fields

cancelation: enum(u3) { /// The thread has not yet been canceled, and is not in a cancelable operation. /// To request cancelation, just set the status to `.canceling`. none = 0b000, /// The thread is parked in a cancelable futex wait or sleep. /// Only applicable if `use_parking_futex` or `use_parking_sleep`. /// To request cancelation, set the status to `.canceling` and unpark the thread. /// To unpark for another reason (futex wake), set the status to `.none` and unpark the thread. parked = 0b001, /// The thread is blocked in a cancelable system call. /// To request cancelation, set the status to `.blocked_canceling` and repeatedly interrupt the system call until the status changes. blocked = 0b011, /// Windows-only: the thread is blocked in an alertable wait via /// `NtDelayExecution`. To request cancelation, set the status to /// `blocked_alertable_canceling` and repeatedly alert the thread /// until the status changes. blocked_alertable = 0b010, /// The thread has an outstanding cancelation request but is not in a cancelable operation. /// When it acknowledges the cancelation, it will set the status to `.canceled`. canceling = 0b110, /// The thread has received and acknowledged a cancelation request. /// If `recancel` is called, the status will revert to `.canceling`, but otherwise, the status /// will not change for the remainder of this task's execution. canceled = 0b111, /// The thread is blocked in a cancelable system call, and is being /// canceled. The thread which triggered the cancelation will send /// signals to this thread until its status changes. blocked_canceling = 0b101, /// Windows-only: the thread is blocked in an alertable wait via /// `NtDelayExecution`, and is being canceled. The thread which /// triggered the cancelation will send signals to this thread /// until its status changes. blocked_alertable_canceling = 0b100, }

The specific values of these enum fields are chosen to simplify the implementation of the transformations we need to apply to this state.

awaitable: AwaitableId

We cannot turn this value back into a pointer. Instead, it exists so that a task can be canceled by a cmpxchg on thread status: if it is running the task we want to cancel, then update the cancelation field.

File

Io/Threaded.zig:842
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
    const Status = packed struct(usize) {
        /// The specific values of these enum fields are chosen to simplify the implementation of
        /// the transformations we need to apply to this state.
        cancelation: enum(u3) {
            /// The thread has not yet been canceled, and is not in a cancelable operation.
            /// To request cancelation, just set the status to `.canceling`.
            none = 0b000,

            /// The thread is parked in a cancelable futex wait or sleep.
            /// Only applicable if `use_parking_futex` or `use_parking_sleep`.
            /// To request cancelation, set the status to `.canceling` and unpark the thread.
            /// To unpark for another reason (futex wake), set the status to `.none` and unpark the thread.
            parked = 0b001,

            /// The thread is blocked in a cancelable system call.
            /// To request cancelation, set the status to `.blocked_canceling` and repeatedly interrupt the system call until the status changes.
            blocked = 0b011,

            /// Windows-only: the thread is blocked in an alertable wait via
            /// `NtDelayExecution`. To request cancelation, set the status to
            /// `blocked_alertable_canceling` and repeatedly alert the thread
            /// until the status changes.
            blocked_alertable = 0b010,

            /// The thread has an outstanding cancelation request but is not in a cancelable operation.
            /// When it acknowledges the cancelation, it will set the status to `.canceled`.
            canceling = 0b110,

            /// The thread has received and acknowledged a cancelation request.
            /// If `recancel` is called, the status will revert to `.canceling`, but otherwise, the status
            /// will not change for the remainder of this task's execution.
            canceled = 0b111,

            /// The thread is blocked in a cancelable system call, and is being
            /// canceled. The thread which triggered the cancelation will send
            /// signals to this thread until its status changes.
            blocked_canceling = 0b101,

            /// Windows-only: the thread is blocked in an alertable wait via
            /// `NtDelayExecution`, and is being canceled. The thread which
            /// triggered the cancelation will send signals to this thread
            /// until its status changes.
            blocked_alertable_canceling = 0b100,
        },

        /// We cannot turn this value back into a pointer. Instead, it exists so that a task can be
        /// canceled by a cmpxchg on thread status: if it is running the task we want to cancel,
        /// then update the `cancelation` field.
        awaitable: AwaitableId,
    }