0

This is a question about the memory order listed in 'c++ concurrency in action'.

First, in listing 5.7; the consequence can be:

Thread A : x.store(true, release)

Thread B : x.load(acquire) returns true, y.load(acquire) returns false

Thread C : y.load(acquire) returns true, x.load(acquire) returns false

Thread D : y.store(true, release)

On the other hand, by 'release sequence':

  • thread A's store -> thread B's x_load and
  • by release sequence, -> thread C's x_load
  • so thread C's x_load must be true, if thread B's y_load is false.

So I think it should be

Thread B : x.load(acquire) returns true, y.load(acquire) returns true

Thread C : y.load(acquire) returns true, x.load(acquire) returns false

or

Thread B : x.load(acquire) returns true, y.load(acquire) returns false

Thread C : y.load(acquire) returns true, x.load(acquire) returns true

Another question:

In listing 7.12 there is a paragraph,

'the easy way to do this is to make the fetch_add() in the successful-return branch use std::memory_order_release and the fetch_add() in the loop-again branch use std::memory_order_acquire. However, this is still overkill: only one thread does the delete , so only that thread needs to do an acquire operation. Thankfully, because fetch_add() is read-modify-write operation, it forms part of the release sequence, so you can do that with an additional load().'

I don't know what this paragraph means; where is the 'release sequence' ?

curiousguy
  • 8,038
  • 2
  • 40
  • 58
최범석
  • 49
  • 4
  • "where is the 'release sequence' ? - in listing 7.12 where you see: if(ptr->internal_count.fetch_add(count_increase, std::memory_order_release)==-count_increase) { delete ptr; }return res; ... – SChepurin Mar 08 '17 at 16:35
  • i thought the release sequence does act like a ***chaining***. if thread A which deletes the node in the stack sends a release memory order to other threads (thread B, thread C), the thread B or C receives the release memory order in the 'ptr->internal_count.load(std::memory_order_acquire) ' and again sends release memory order to other threads. but i think there is no reason why the thread B or C sends the release memory order again.please tell me what's wrong ., – 최범석 Mar 08 '17 at 22:31
  • Your primary question was [asked and answered here](https://stackoverflow.com/questions/48383867/acquire-release-semantics-with-4-threads/48386173). – Drew Dormann Jun 27 '18 at 22:43

0 Answers0