Hmm, shouldn't `WRITING_FLAG` be a lock rather than just a bool?