Struct ThreadParker
pub struct ThreadParker { /* private fields */ }Expand description
只有创建线程可以停放和消费通知;不可跨线程转移或共享。
提交、任务唤醒、取消和关闭的实际发布者通过ThreadNotifier通知。
策略、来源重查和最迟再次检查时刻由执行器负责,本对象不判断空闲,不访问队列。
Implementations§
§impl ThreadParker
impl ThreadParker
pub fn new() -> Self
pub fn new() -> Self
绑定当前线程,准备一份共享通知状态,初始notified=true以安排首次检查。
pub fn notifier(&self) -> ThreadNotifier
pub fn notifier(&self) -> ThreadNotifier
克隆同一原线程的受限通知,不产生另一个停放拥有者。
pub fn owner_thread(&self) -> ThreadId
pub fn owner_thread(&self) -> ThreadId
读取固定原线程身份,不取得其它线程推进权。
pub fn is_notified(&self) -> bool
pub fn is_notified(&self) -> bool
Acquire取样,不消费通知,不证明下一瞬间可以休眠。
pub fn take_notification(&mut self) -> bool
pub fn take_notification(&mut self) -> bool
原线程一次Acquire交换,取走现有通知;取走后必须实际重新检查工作。
pub fn park_timeout(&mut self, duration: Duration) -> ThreadParkResult
pub fn park_timeout(&mut self, duration: Duration) -> ThreadParkResult
通知存在则直接返回,否则限时停放,返回后再次取得通知并重新分类。
duration是调用方选定的本次上限,零不等待。休眠策略与定时来源最迟检查时刻须
在调用前组合;本层不擅自延长上限。最后通知检查到实际park之间不得执行用户回调、
日志或另一个park,以免其它代码消费同一线程permit。任何返回都需要上层重查来源。
系统调度可能延迟线程恢复,本函数不承诺墙钟硬上界。
Trait Implementations§
Auto Trait Implementations§
impl !Send for ThreadParker
impl !Sync for ThreadParker
impl Forget for ThreadParker
impl Freeze for ThreadParker
impl Move for ThreadParker
impl RefUnwindSafe for ThreadParker
impl Unpin for ThreadParker
impl UnsafeUnpin for ThreadParker
impl UnwindSafe for ThreadParker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more