Use Nikhar's incremental calculation, and double-checked-locking to reduce contention.