Small threading fixes

I've fixed the only thing that TSan complained about during my testing, as well as a race condition in the initialization of the queue which TSan didn't pick up. The latter was causing a crash on OSX.