Yes, I think is better to use semaphores to implement thread safety. It is more common than flock use. I have never used flock  :)
NTC