Consider the following scenario:
Thread A fills a buffer and sets a flag (whose initial value is 0):
pmem_memcpy_persist(pmembuf, ...);
While thread B waits for the flag and then takes a snapshot of pmembuf:
while (1 != flag);
memcpy(tmpbuf, pmembuf, ...);
When the buffer alignment and copy size allow pmem_memcpy_persist() to use only non-temporal instructions and if drain does not include a fence (i.e. CLFLUSH only), then, in our testing, thread B will sometimes see stale contents in pmembuf (that is, values held before thread A's memcpy).
An SFENCE in thread A after the copy but before the flag set seems to ensure that thread B sees the new values in pmembuf.
What is the expected/intended behavior of pmem_memcpy_persist() in this regard? Should pmem_memcpy_persist() include an SFENCE or similar?
Thanks!
Brian