correct locking in stdio functions that tried to be lock-free