문제

I am trying to follow this article in the section about publication safety. My case is no different than the trivial example in the article, but the "published" data is not a single value, but several fields in a struct. The publisher will write each field singularly, so by wrapping up each write with a store with memory_order_release I should be ok.

The consumer will first check with memory_order_acquire that the data is ready. Then, I'm tempted to use a memcpy to copy the entire published struct somewhere else (because that fits better into the rest of the pre-existing code), but this doesn't seem to be safe because I cannot specify the memory model. Is this just paranoia or can it be a serious problem?

Suggestions specific to amd64/x86 accepted.

도움이 되었습니까?

해결책

Acquire semantics mean that loads later in program order won't get re-ordered before the barrier, regardless of what semantics you ask for on the later loads. So I believe that using memcpy to read the structure after an acquire barrier is safe.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top