flock instead of self-made locking functions