Create a new counter array of Size counters. All counters in the array are initially set to zero.
Argument Opts is a list of the following possible options:
atomics (Default) -
Counters will be sequentially consistent. If write operation A is done sequentially before write operation B, then a concurrent reader may see the result of none of them, only A, or both A and B. It cannot see the result of only B.
write_concurrency -
This is an optimization to achieve very efficient concurrent add and sub operations at the expense of potential read inconsistency and memory consumption per counter.
Read operations may see sequentially inconsistent results with regard to concurrent write operations. Even if write operation A is done sequentially before write operation B, a concurrent reader may see any combination of A and B, including only B. A read operation is only guaranteed to see all writes done sequentially before the read. No writes are ever lost, but will eventually all be seen.
The typical use case for write_concurrency is when concurrent calls to add and sub toward the same counters are very frequent, while calls to get and put are much less frequent. The lack of absolute read consistency must also be acceptable.
Counters are not tied to the current process and are automatically garbage collected when they are no longer referenced.