Working version with two types of atomic counters and sorting mechanisms