Thread unsafe implementation of cyclic buffer