Thread safe queue and circular buffer