RFR (M) 8195099: Concurrent safe-memory-reclamation mechanism (original) (raw)
David Holmes david.holmes at oracle.com
Wed Apr 11 12:03:01 UTC 2018
- Previous message: RFR (M) 8195099: Concurrent safe-memory-reclamation mechanism
- Next message: RFR (M) 8195099: Concurrent safe-memory-reclamation mechanism
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 11/04/2018 9:38 PM, Robbin Ehn wrote:
Hi,
On 04/11/2018 12:57 PM, David Holmes wrote:
Sorry no, I don't understand what this counter is doing at all. I feel I need to see what is between the begin/end critical section for this to make any sense to me. And to see what the writer actually does. From gtest:
Thanks for that. Okay I have a better sense of how the access to the data completes the handshake.
Does the naming/terminology come from some existing mechanism? I find it somewhat odd and not really descriptive of the operation..
Thanks, David
Read side do: 49 GlobalCounter::criticalsectionbegin(this); 50 volatile TestData* test = OrderAccess::loadacquire(test); 51 long value = OrderAccess::loadacquire(&test->testvalue); 52 ASSERTEQ(value, GOOD); 53 GlobalCounter::criticalsectionend(this); Write side do: 101 volatile TestData* freetmp = test; 102 tmp = new TestData(); 103 tmp->testvalue = GOOD; 104 OrderAccess::releasestore(&test, tmp); 105 GlobalCounter::writesynchronize(); 106 freetmp->testvalue = BAD; 107 delete freetmp;
If a reader is context switch between line 50 and 51, it will have a cached value of the pointer "test", thus no one should free it. Before freeing the writer calls writesynchronize which guarantees that no reader can see the old pointer and can then free it. If the reader is context switch inside criticalsectionbegin this does not matter since the fence in criticalsectionbegin prohibits the load of test pointer from floating up. If writesynchronize is done before this reader gets back on CPU it will see the new value but have an counter of an old generation. If it gets back on CPU before writesynchronize I will see the old pointer. If we call the pointer values TESTgen1, TESTgen2, ... testpointer starts equal to TESTgen1 and generation starts at 1. Writer: tmppointer = testpointer Writer: testpointer = TESTgen2 Reader: load global counter (fetches 1) Reader: context switched out Writer: writesynchronized generation = 2, and do not see the reader. Reader: store local counter to 1 // critical section begin Reader: load testpointer (TESTgen2) // This load will always happen after the store to local counter Writer: free tmppointer (TESTgen1) // ABA safe Writer: tmppointer = testpointer Writer: testpointer = TESTgen3 Writer: writesynchronized generation = 3, and sees on old reader => wait. Reader: store local counter OFF // critical section end Writer: writesynchronized now finishes. Writer: free tmppointer (TESTgen2) // ABA safe /Robbin
David -----
- Previous message: RFR (M) 8195099: Concurrent safe-memory-reclamation mechanism
- Next message: RFR (M) 8195099: Concurrent safe-memory-reclamation mechanism
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]