Imagine the following code: ... lot of writes writes to the buffer buffer.putInt(a_offset,a_value) (1) buffer.putRelease(b_offset,b_value) (2) releaseFence() (3) buffer.putInt(c_offset,c_value) (4)
Buffer is a chunk of memory that is shared with another process and the writes need to be seen in order. So when 'b' is seen, 'a' should be seen. And when 'c' is seen, 'b' should be seen. There is no other synchronization. All offsets are guaranteed to be naturally aligned. All the putInts are plain puts (using Unsafe). The putRelease (2) will ensure that 'a' is seen before 'b', and it will ensure atomicity and visibility of 'b' (so the appropriate compiler and memory fences where needed). The releaseFence (3) will ensure that b is seen before c. My question is about (4). Since it is a plain store, the compiler can do a ton of trickery including the delay of visibility of (4). Is my understanding correct and is there anything else that could go wrong? What would be the lowest memory access mode that would resolve this problem? My guess is that the last putInt, should be a putIntOpaque. Probably it would be better to replace (4), but a putIntRelease and get rid of the releaseFence since then the above problem will be solved. -- You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion, visit https://groups.google.com/d/msgid/mechanical-sympathy/CAGuAWdCsw8RoQYesXtH5J5M4MiOn9eBhCTNzd%2BXGTA_JUcGu1w%40mail.gmail.com.
