Adding a buffer class which is thread-safe if there are only one producer and one consumer