bgjobs: fix a couple of thread safetly issues.