Reputation: 1642
I am learning RDMA verbs in C (libibverbs
).
One question I have is after having polled a Receive Work Completion with a Receive RDMA write with immediate (IBV_WC_RECV_RDMA_WITH_IMM
), the compiler might not see that the content of the receiving buffer has changed. So, do we need to declare the receiving buffer volatile
? AFAI, this is one usage of volatile
: the content of the variable can be modified by an external source (here, RDMA hardware).
An example of code:
void receive(volatile char* receiving_buffer, size_t size, ibv_cq *cq)
{
ibv_wc wc;
int n = 0;
while(n == 0) n = ibv_poll_cq(cq, 1, &wc);
assert(wc.status == IBV_WC_SUCCESS);
assert(wc.opcode == IBV_WC_RDMA_WRITE && (wc.wc_flags & IBV_WC_WITH_IMM));
// Prevent buffer overflow
receiving_buffer[size - 1] = '\0';
printf("%s\n", receiving_buffer);
}
Is qualifying receiving_buffer
with volatile
needed?
I guess the answer will be the same for RDMA write or RDMA send.
Upvotes: 0
Views: 58