From fbb5cba355980a43b08cd74ea274d6053c99c4af Mon Sep 17 00:00:00 2001 From: Artemciy Date: Thu, 7 Nov 2019 09:29:24 +0300 Subject: [PATCH] Edit DuplexMutex description #561 --- mm2src/common/duplex_mutex.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mm2src/common/duplex_mutex.rs b/mm2src/common/duplex_mutex.rs index 7031963ba0..1ec5381d66 100644 --- a/mm2src/common/duplex_mutex.rs +++ b/mm2src/common/duplex_mutex.rs @@ -85,17 +85,17 @@ impl Impl { /// A mutual exclusion primitive that can be used from both the synchronous and asynchronous contexts. /// -/// There is a problem with existing primitives. +/// There is a problem with existing primitives: /// Synchronous Mutex can not be used reliably from WASM since threading there is new. /// Asynchronous Mutex is only compatible with fully asynchronous code /// because `block_on` will panic under a layered async->sync->block_on(lock), /// but making everything asynchronous would lead to bloated machine code, -/// obscure errors and restraints and slowed compilation speed. +/// obscure errors, restraints and slowed compilation speed. /// -/// DuplexMutex bridges this gap by being useable in both contexts. +/// DuplexMutex bridges this gap by being useable in both contexts: /// In the synchronous context it will spin. -/// In the asynchronous context it will also wait with the `Timer`, -/// allowing the greed thread holding the lock to resurface even in situations +/// In the asynchronous context it will wait with the `Timer`, +/// allowing the green thread holding the lock to resurface even in situations /// when both the holder and the entrant are on the same system thread. pub struct DuplexMutex { pimpl: Arc> @@ -115,8 +115,10 @@ impl DuplexMutex { impl DuplexMutex { /// Synchronous spinlock. - /// Should only be used when the mutex contention happens from different system threads - /// (like when the mutex guard does not cross green thread boundaries). + /// Should be used when the mutex contention happens from different system threads + /// (like when the mutex guard does not cross green thread boundaries). + /// Using spinlock from two green threads running on the same system thread might result in a deadlock, + /// but that might be mitigated by handling the timeout `Err`. pub fn spinlock (&self, timeout_ms: i64) -> Result, String> { try_s! (self.pimpl.spinlock (timeout_ms)); Ok (DuplexMutexGuard {mutex: self})