is it correct to use memory_order_relaxed in ProducerConsumerQueue::read

Showing 1-2 of 2 messages
is it correct to use memory_order_relaxed in ProducerConsumerQueue::read Derek 6/26/12 3:00 PM
ProducerConsumerQueue::read has below code in the beginning to check if queue is empty, memory_order_relaxed looks bit suspicious. Presume the reason isEmpty is not called here is to avoid load readIndex twice, but isEmpty uses memory_order_consume on both readIndex and writeIndex.

    auto const currentRead = readIndex_.load(std::memory_order_relaxed);
    if (currentRead == writeIndex_.load(std::memory_order_acquire)) {
      // queue is empty
      return false;
    }
Re: is it correct to use memory_order_relaxed in ProducerConsumerQueue::read Derek 6/26/12 3:04 PM

realized I was wrong when looking at write function. Since read will only be called by the reader thread, and readIndex is increased by reader thread only, memory_order_relaxed should be fine for reader thread.