Fixed bug in circular_buffer_debug where buffer data was off by one.
Implemented multithreading support; read and write operations are atomic.