diff options
-rw-r--r-- | crates/ra_vfs/src/io.rs | 10 |
1 files changed, 8 insertions, 2 deletions
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); | |||
50 | // Like thread::JoinHandle, but joins the thread on drop. | 50 | // Like thread::JoinHandle, but joins the thread on drop. |
51 | // | 51 | // |
52 | // This is useful because it guarantees the absence of run-away threads, even if | 52 | // This is useful because it guarantees the absence of run-away threads, even if |
53 | // code panics. This is important, because we might seem panics in the test and | 53 | // code panics. This is important, because we might see panics in the test and |
54 | // we might be used in an IDE context, where a failed component is just | 54 | // we might be used in an IDE context, where a failed component is just |
55 | // restarted. | 55 | // restarted. |
56 | // | 56 | // |
@@ -75,7 +75,13 @@ impl Drop for ScopedThread { | |||
75 | } | 75 | } |
76 | 76 | ||
77 | pub(crate) struct Worker { | 77 | pub(crate) struct Worker { |
78 | // XXX: it's important to drop `sender` before `_thread` to avoid deadlock. | 78 | // XXX: field order is significant here. |
79 | // | ||
80 | // In Rust, fields are dropped in the declaration order, and we rely on this | ||
81 | // here. We must close sender first, so that the `thread` (who holds the | ||
82 | // opposite side of the channel) noticed shutdown. Then, we must join the | ||
83 | // thread, but we must keep receiver alive so that the thread does not | ||
84 | // panic. | ||
79 | pub(crate) sender: Sender<Task>, | 85 | pub(crate) sender: Sender<Task>, |
80 | _thread: ScopedThread, | 86 | _thread: ScopedThread, |
81 | pub(crate) receiver: Receiver<VfsTask>, | 87 | pub(crate) receiver: Receiver<VfsTask>, |