[−][src]Struct sunrise_kernel::process::ProcessStateData
Data related to the (user-visible) state the current process is in. The maternity is stored here to ensure there is no race condition between setting the state to Exited and adding threads to the maternity.
Fields
signaled: bool
Whether the process is currently in a signaled state. Set to true when changing the state, and false when the user calls reset_signal(). Note that once the Exited state is reached, the process is permanently signaled.
state: ProcessState
The current state of the process.
waiting_threads: Vec<Arc<ThreadStruct>>
Threads waiting on this process to get signaled.
thread_maternity: Vec<Arc<ThreadStruct>>
An array of the created but not yet started threads.
When we create a thread, we return a handle to userspace containing a weak reference to the thread, which has not been added to the schedule queue yet. To prevent it from being dropped, we must keep at least 1 strong reference somewhere. This is the job of the maternity. It holds references to threads that no one has for now. When a thread is started, its only strong reference is removed from the maternity, and put in the scheduler, which is now in charge of keeping it alive (or not).
Note that we store in the process struct a strong reference to a thread, which itself has a strong reference to the same process struct. This creates a cycle, and we loose the behaviour of "a process is dropped when its last living thread is dropped". The non-started threads will keep the process struct alive. This makes it possible to pass a non-started thread handle to another process, and let it start it for us, even after our last living thread has died.
However, because of this, if a thread creates other threads, does not share the handles, and dies before starting them, the process struct will be kept alive indefinitely by those non-started threads that no one can start, and the process will stay that way until it is explicitly stopped from outside.
Implementations
impl ProcessStateData
[src]
fn set_state(&mut self, newstate: ProcessState)
[src]
Sets the state to the given new state, and signal the process, causing any threads waiting on the process to get woken up.
fn signal(&mut self)
[src]
Set the process to the signaled state, and wake up any thread waiting on this process to get signaled.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ProcessStateData
impl Send for ProcessStateData
impl Sync for ProcessStateData
impl Unpin for ProcessStateData
impl !UnwindSafe for ProcessStateData
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,