Skip to content

Commit 8004ce2

Browse files
committed
[libc] Move thread sync when closing port earlier
Summary: This synchronization should be done before we handle the logic relating to closing the port. This isn't majorly important now but it would break if we ever decided to run a server on the GPU.
1 parent 5ae143d commit 8004ce2

File tree

1 file changed

+4
-4
lines changed
  • libc/src/__support/RPC

1 file changed

+4
-4
lines changed

libc/src/__support/RPC/rpc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,9 @@ template <bool Invert> struct Process {
198198
/// convergent, otherwise the compiler will sink the store and deadlock.
199199
[[clang::convergent]] LIBC_INLINE void unlock(uint64_t lane_mask,
200200
uint32_t index) {
201-
// Do not move any writes past the unlock
201+
// Do not move any writes past the unlock.
202202
atomic_thread_fence(cpp::MemoryOrder::RELEASE);
203203

204-
// Wait for other threads in the warp to finish using the lock
205-
gpu::sync_lane(lane_mask);
206-
207204
// Use exactly one thread to clear the nth bit in the lock array Must
208205
// restrict to a single thread to avoid one thread dropping the lock, then
209206
// an unrelated warp claiming the lock, then a second thread in this warp
@@ -331,6 +328,9 @@ template <bool T> struct Port {
331328
LIBC_INLINE uint16_t get_index() const { return index; }
332329

333330
LIBC_INLINE void close() {
331+
// Wait for all lanes to finish using the port.
332+
gpu::sync_lane(lane_mask);
333+
334334
// The server is passive, if it own the buffer when it closes we need to
335335
// give ownership back to the client.
336336
if (owns_buffer && T)

0 commit comments

Comments
 (0)