Implementation of thread-safe Circle Buffer