add proper fuxed-based locking for stdio