diff --git a/lib/pls/include/pls/internal/scheduling/lock_free/traded_cas_field.h b/lib/pls/include/pls/internal/scheduling/lock_free/traded_cas_field.h index 4318b1a..402dc62 100644 --- a/lib/pls/include/pls/internal/scheduling/lock_free/traded_cas_field.h +++ b/lib/pls/include/pls/internal/scheduling/lock_free/traded_cas_field.h @@ -46,8 +46,6 @@ struct traded_cas_field { return stamp_; } [[nodiscard]] unsigned long get_trade_request_thread_id() const { - PLS_ASSERT(is_filled_with_trade_request() || is_filled_with_object(), - "Must only read out the tag when the traded field contains one."); return trade_request_thread_id_ - 1; } @@ -62,6 +60,9 @@ struct traded_cas_field { [[nodiscard]] bool is_filled_with_object() const { return non_empty_flag_ && traded_task_id_; } + [[nodiscard]] bool object_was_traded_in() const { + return traded_task_id_ != 0; + } [[nodiscard]] bool is_empty() const { return !non_empty_flag_; } diff --git a/lib/pls/src/internal/scheduling/lock_free/external_trading_deque.cpp b/lib/pls/src/internal/scheduling/lock_free/external_trading_deque.cpp index 2e4dbed..b1883b0 100644 --- a/lib/pls/src/internal/scheduling/lock_free/external_trading_deque.cpp +++ b/lib/pls/src/internal/scheduling/lock_free/external_trading_deque.cpp @@ -135,7 +135,8 @@ task *external_trading_deque::pop_top(task *offered_task, peek_result peek_resul std::memory_order_acq_rel); return result; } else { - if (expected_sync_cas_field.is_filled_with_object() && expected_sync_cas_field.get_stamp() == expected_top.stamp_ + if (expected_sync_cas_field.object_was_traded_in() + && expected_sync_cas_field.get_stamp() == expected_top.stamp_ && expected_sync_cas_field.get_trade_request_thread_id() == thread_id_) { top_.compare_exchange_strong(expected_top, {expected_top.stamp_ + 1, expected_top.value_ + 1},