A ThreadsafeCounter is simply a counter (based on a long) which
may be incremented in a threadsafe manner.
There is only one constructor, the default constructor:
ThreadsafeCounter() -- create new counter starting at zero.
There is only one operation:
TCS.myAdvance(n) -- increment the counter by n, and
return the value of the counter prior to incrementing.
Note that myAdvance is likely to be quite slow as it uses mutexes.
A ThreadsafeCounter may be printed; this is intended primarily to
permit debugging.
I copied the code from a BOOST example. It's so simple there are obviously no deficiencies!
operator<< is probably not threadsafe (but does that matter?)
No check for overflow!
You cannot query the counter's value without incrementing it.
2012