The Oracle Gods wrote:Actions in a thread prior to placing an object into any concurrent collection happen-before actions subsequent to the access or removal of that element from the collection in another thread.
"Il y a peu de choses qui me soient impossibles..."
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Tim Holloway wrote:...a proper synchronization mechanism would still be required.
"Il y a peu de choses qui me soient impossibles..."
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:What is there in C++ under Windows that creates the same happens-before relationship to memory access in one thread compared to another as there is in Java (as described for any of the collections in the java.util.concurrent package)?
Steffe Wilson wrote:If I have understood you correctly then the mechanism you are looking for is called a 'condition variable'.
Bjarne Stroustrup wrote:I suspect that after reading about the problems with and techniques for managing shared data, you may become sympathetic to my view that explicitly shared data is best avoided.
Actions in a thread prior to placing an object into any concurrent
collection happen-before actions subsequent to the access or
removal of that element from the collection in another thread.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:
Steffe Wilson wrote:If I have understood you correctly then the mechanism you are looking for is called a 'condition variable'.
Thanks, but that's not quite it, Steffe. A condition variable is a synchronization construct, and it does define a happens-before relationship, but it doesn't guarantee that a write to shared memory is readable by the code in the thread that has a happens-after relationship with the code that sets the condition variable. The only way to do that is to be sure that all writes in the code that happens-before the condition variable (which, in my case, is a BlockingQueue, when I use Java) are written through cache memory back to main memory and that any cached copy of that memory previously loaded by the second thread is invalidated before the condition variable is set. This guarantees that, when the condition variable is set, all writes by the first thread that took place before the first thread set the condition variable will be visible to the second thread, after the condition variable is set.
Steffe Wilson wrote:A condition variable has to be used within a mutex section (recall that CV.wait takes the mutex as an arg) and taking hold of a mutex applies an implicit memory barrier which flushes the cache.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:Can you point me to some online documentation about this?
What's gotten into you? Could it be this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|