darion-yaphet commented on code in PR #3738:
URL: https://github.com/apache/brpc/pull/3738#discussion_r4581785839


##########
test/brpc_event_dispatcher_unittest.cpp:
##########
@@ -130,6 +130,67 @@ TEST_F(EventDispatcherTest, has_epollrdhup) {
     LOG(INFO) << brpc::has_epollrdhup;
 }
 
+TEST_F(EventDispatcherTest, start_stop_updates_running_state) {
+    brpc::EventDispatcher dispatcher;
+    ASSERT_EQ(0, dispatcher.Start(nullptr));
+    ASSERT_TRUE(dispatcher.Running());
+    dispatcher.Stop();
+    dispatcher.Join();
+    ASSERT_FALSE(dispatcher.Running());
+}
+
+struct DispatcherStopRaceArgs {
+    brpc::EventDispatcher* dispatcher;
+    butil::atomic<bool> reader_started;
+    butil::atomic<bool> stop_requested;
+    butil::atomic<bool> reader_polling;
+    butil::atomic<bool> stop_completed;
+    butil::atomic<bool> reader_finished;
+
+    DispatcherStopRaceArgs()
+        : dispatcher(nullptr)
+        , reader_started(false)
+        , stop_requested(false)
+        , reader_polling(false)
+        , stop_completed(false)
+        , reader_finished(false) {}
+};
+
+void* poll_dispatcher_running(void* arg) {
+    DispatcherStopRaceArgs* args = static_cast<DispatcherStopRaceArgs*>(arg);
+    args->reader_started.store(true, butil::memory_order_release);
+    while (!args->stop_requested.load(butil::memory_order_acquire)) {
+    }
+    args->reader_polling.store(true, butil::memory_order_release);

Review Comment:
   The `reader_polling` flag is set before calling `Running()`. When the main 
thread sees it, it might first execute `Stop()` before the reading thread 
actually calls `Running()`. Therefore, the test does not guarantee that every 
time it results in unsynchronized reading and writing. Ordinary operation 
through this test cannot prove that the fix is complete.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to