zanmato1984 commented on code in PR #40237:
URL: https://github.com/apache/arrow/pull/40237#discussion_r1503033541


##########
cpp/src/arrow/array/data.cc:
##########
@@ -286,8 +286,10 @@ namespace {
 template <typename offset_type>
 BufferSpan OffsetsForScalar(uint8_t* scratch_space, offset_type value_size) {
   auto* offsets = reinterpret_cast<offset_type*>(scratch_space);
-  offsets[0] = 0;
-  offsets[1] = static_cast<offset_type>(value_size);
+  reinterpret_cast<std::atomic<offset_type>*>(&offsets[0])
+      ->store(0, std::memory_order_relaxed);
+  reinterpret_cast<std::atomic<offset_type>*>(&offsets[1])
+      ->store(static_cast<offset_type>(value_size), std::memory_order_relaxed);

Review Comment:
   Well, the reason for the extra reinterpret casts is that: I'm not sure if it 
is guaranteed in C++ that `sizeof(std::atomic<offset_type>)` is the same as 
`sizeof(offset_type)`. If they are not the same, the pointer will be wrongly 
offset-ed.



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