Implementing ping pong buffers