4 Epoch Queue
Terry Kim редактировал(а) эту страницу 2017-02-05 20:37:17 -08:00

How Epoch Queue works

Epoch Queue is an array where its index represents time (epoch time), ti, which is always increasing. Its value represents reference counts at ti.

In the following code, when GetContext() is called, the reference count at that epoch time is incremented by 1. Note that this requires a lock for a brief time, but after this, any Get() calls on any hashtables are lock-free.

    L4::LocalMemory::HashTableService service;

    // Add hash tables, etc.

    auto context = service.GetContext();
    auto& hashTable = context[hashTableIndex];
    auto record1 = hashTable.Get(...);

Now, let's assume that the record1 in the above code gets deleted by another thread at the same epoch time. This record is not deleted from the memory (but it's immediately invisible from the hash table, meaning another Get() on this record will return an empty record) until reference count becomes zero (when the context object gets destroyed). Therefore, record1 above is guaranteed to point to the correct record.