Fix crash when compiled against qt5

qt5 disallows unlocking an already-unlocked mutex. Fixed the logic for the BulkWriter thread. There's more cleanup to do for reliability but this way it at least runs.