Fixed bug in sync_pq that had to do with closing.

Using an atomic<bool> to close the queue did not
work as expected. This was revlealed in my latest
test addition. Buy locking the queue before closing
this problem was solved. Without any threads pulling
from the queue could deadlock as they missed the
close signal.