darion-yaphet commented on code in PR #3689:
URL: https://github.com/apache/brpc/pull/3689#discussion_r4412543210
##########
test/bthread_id_unittest.cpp:
##########
@@ -112,6 +114,37 @@ TEST(BthreadIdTest, join_before_destroy) {
ASSERT_EQ(1UL, non_null_ret);
}
+struct JoinRaceArgs {
+ bthread_id_t id;
+ std::atomic<bool> entered;
+};
+
+void* join_race_waiter(void* arg) {
+ JoinRaceArgs* args = static_cast<JoinRaceArgs*>(arg);
+ args->entered.store(true, std::memory_order_release);
Review Comment:
The waiting thread sets entered to true before calling bthread_id_join().
Therefore, the following sequence may occur:
1. The waiting thread sets entered = true and is then suspended by the
scheduler;
2. The main thread observes the flag and completes the locking and
destruction of the ID;
3. The waiting thread resumes, calls join() and immediately returns.
In this case, the test passes, but there is no target competition between
the reading of the butex_wait() status and the writing of the destruction
status.
--
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]