lriggs commented on code in PR #53160:
URL: https://github.com/apache/arrow/pull/53160#discussion_r4362244204
##########
cpp/src/arrow/compute/kernels/scalar_string_test.cc:
##########
@@ -1927,6 +2024,53 @@ TYPED_TEST(TestBaseBinaryKernels, MatchLikeEscaping) {
this->CheckUnary("match_like", R"(["\n\tfoo\t", "\n\t", "\n"])", boolean(),
"[true, true, false]", &escape_sequences);
}
+
+TYPED_TEST(TestBaseBinaryKernels, MatchLikeConcurrentFirstUse) {
+ auto in_schema = schema({field("x", this->type())});
+ MatchSubstringOptions options{"%ab%"};
+ auto expr = call("match_like", {field_ref("x")}, options);
+ ASSERT_OK_AND_ASSIGN(auto bound_expr, expr.Bind(*in_schema));
+
+ Datum input =
+ ArrayFromJSON(this->type(), R"(["abc", "acb", "cab", null, "bac",
"AB"])");
+ ExecBatch batch({input}, 6);
+
+ constexpr int kNumThreads = 16;
+ std::vector<std::thread> threads;
+ std::vector<Result<Datum>> results(kNumThreads);
+ // Synchronize threads at a two-phase barrier so that all threads are
actively
+ // waiting before any thread begins execution, guaranteeing a true concurrent
+ // first-initialization race on the cached matcher.
+ std::atomic<int> waiting{0};
+ std::atomic<bool> go{false};
+
+ for (int i = 0; i < kNumThreads; ++i) {
+ threads.emplace_back([&, i]() {
+ // Signal arrival at the barrier and spin-wait until all threads are
ready.
+ waiting.fetch_add(1, std::memory_order_relaxed);
+ while (!go.load(std::memory_order_acquire)) {
+ std::this_thread::yield();
+ }
+ results[i] = ExecuteScalarExpression(bound_expr, batch);
+ });
+ }
Review Comment:
Since this is repeated across the three tests it would be nice to generalize
to a helper function if its not too much trouble. But Im ok with it was it is
also.
--
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]