All problems
Epoch-Based Reclamation Counter
Problem
Count reclaimed objects in an epoch-based reclamation scheme.
num_threads threads pin epochs; all start at epoch 0. Operations are "retire" (add an object at the current global epoch), "advance" (increment the global epoch), "pin" (values[i] is the thread that adopts the global epoch), and "reclaim" (free every retired object whose epoch is below the minimum pinned epoch and record how many were freed).
Return the list of freed counts.
Hint
Objects retire at the global epoch and are reclaimable once every pinned epoch has passed.
Test cases
case 1
in: [1,["retire","advance","pin","reclaim"],[0,0,0,0]]
expected: [1]
case 2
in: [1,["retire","reclaim"],[0,0]]
expected: [0]
case 3
in: [2,["retire","advance","pin","retire","advance","pin","reclaim"],[0,0,0,0,0,1,0]]
expected: [1]
case 4
in: [1,["retire","advance","advance","pin","reclaim","reclaim"],[0,0,0,0,0,0]]
expected: [1,0]
Starter codePython
def epoch_ops(num_threads, operations, values):
# Your code here
pass4 test cases · run your code against them in the editor