fix data races by locking in functions which do not lock