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:
Setting `reader_polling` here does not guarantee that the reader has entered
`Running()` before `Stop()` executes. However, execution order alone does not
establish a happens-before relationship. Have you verified that this test
reports the race with the original `volatile` implementation under TSAN and
passes with the atomic implementation?
--
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]