I think unlock is not required; flock is associated with fd, which will be closed when ofstream goes out of scope or ofs.close() is called.