rtpsw commented on code in PR #34392:
URL: https://github.com/apache/arrow/pull/34392#discussion_r1169726852


##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -249,12 +250,18 @@ struct MemoStore {
 
   void swap(MemoStore& memo) {
     std::swap(no_future_, memo.no_future_);
-    std::swap(current_time_, memo.current_time_);
+    current_time_ = memo.current_time_.exchange((OnType)current_time_);
     entries_.swap(memo.entries_);
     future_entries_.swap(memo.future_entries_);
     times_.swap(memo.times_);
   }
 
+  void UpdateTime(OnType ts) {
+    OnType prev_time = current_time_;
+    while (prev_time < ts && current_time_.compare_exchange_weak(prev_time, 
ts)) {

Review Comment:
   This is because `compare_and_exchange_weak` (see 
[doc](https://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange)) may 
not find the expected value of `prev_time` from line 260 by the time the loop 
is executed due to a race condition (expected to be rare). In this case `false` 
is returned and `prev_time` is updated to the value of `current_time_`. Then, 
another iteration is tried. This is normal CAS-loop logic.



-- 
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]

Reply via email to