lock and unlock mutex around fortran function calls