[io] Fix data race in Mac file watcher.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61474
Change-Id: I15596b01fab51a8e420aea1dc41868f22785c019
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449061
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
diff --git a/runtime/bin/file_system_watcher_macos.cc b/runtime/bin/file_system_watcher_macos.cc
index bbe708d..4e4fb47 100644
--- a/runtime/bin/file_system_watcher_macos.cc
+++ b/runtime/bin/file_system_watcher_macos.cc
@@ -132,7 +132,7 @@
     DISALLOW_COPY_AND_ASSIGN(Node);
   };
 
-  FSEventsWatcher() : run_loop_(0) { Start(); }
+  FSEventsWatcher() : monitor_(), run_loop_(nullptr), owner_() { Start(); }
 
   void Start() {
     Thread::Start("dart:io FileWatcher", Run, reinterpret_cast<uword>(this));
@@ -147,11 +147,12 @@
     FSEventsWatcher* watcher = reinterpret_cast<FSEventsWatcher*>(arg);
     // Only checked in debug mode.
     watcher->owner_.Acquire();
-    watcher->run_loop_ = CFRunLoopGetCurrent();
-    CFRetain(watcher->run_loop_);
+    CFRunLoopRef loop = CFRunLoopGetCurrent();
+    CFRetain(loop);
 
     // Notify, as the run-loop is set.
     watcher->monitor().Enter();
+    watcher->run_loop_ = loop;
     watcher->monitor().Notify();
     watcher->monitor().Exit();