It is easy to start a process from a specific directory with Lwt using the functions Sys.getpwd
, Lwt_unix.chdir
and Lwt_process.exec
:
- Use
Sys.getpwd
to save the current working directory - Use
Lwt_unix.chdir
to change to the specific directory - Use
Lwt_process.exec
to start the external process - Use
Lwt_unix.chdir
to change to the saved current working directory
This logic is flawed, for it allows the scheduler to run another thread after after the first call to Lwt_unix.chdir
and after the call to Lwt_process.exec
which would lead this thread to be run in special directory rather than in the saved current directory. Is it possible to easily start a process from a special directory with Lwt without introducing a race condition such as the one I describe?