From d93097a4936b9eea98e4759fa2fde3a052acfb42 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 18 Feb 2019 16:20:12 +0300 Subject: better comments --- crates/ra_vfs/src/io.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'crates/ra_vfs') diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs index b6a057697..5969ee0d0 100644 --- a/crates/ra_vfs/src/io.rs +++ b/crates/ra_vfs/src/io.rs @@ -50,7 +50,7 @@ const WATCHER_DELAY: Duration = Duration::from_millis(250); // Like thread::JoinHandle, but joins the thread on drop. // // This is useful because it guarantees the absence of run-away threads, even if -// code panics. This is important, because we might seem panics in the test and +// code panics. This is important, because we might see panics in the test and // we might be used in an IDE context, where a failed component is just // restarted. // @@ -75,7 +75,13 @@ impl Drop for ScopedThread { } pub(crate) struct Worker { - // XXX: it's important to drop `sender` before `_thread` to avoid deadlock. + // XXX: field order is significant here. + // + // In Rust, fields are dropped in the declaration order, and we rely on this + // here. We must close sender first, so that the `thread` (who holds the + // opposite side of the channel) noticed shutdown. Then, we must join the + // thread, but we must keep receiver alive so that the thread does not + // panic. pub(crate) sender: Sender, _thread: ScopedThread, pub(crate) receiver: Receiver, -- cgit v1.2.3