I want to implement a silly filesystem using ocamlfuse. In the silly filesystem implementation, everything is in the Lwt monad.
ocamlfuse (and FUSE itself) allow working in two different modes: single-threaded and multithreaded.
ocamlfuse has an “event loop” I believe. If we stick to single-threaded FUSE/ocamlfuse usage, the main thread repeatedly takes a request and services it.
Now, if the implementation is using Lwt, there seem to be two problems: 1) we can’t run the top-level Lwt_main.run loop in the main thread, because that is being used for the ocamlfuse event loop, and 2) after servicing a request using Lwt code, it is not immediately obvious how to extract a result from the Lwt monad and return it to the ocamlfuse event loop (?).
Regarding 1), can I just create a new Thread.t and run the Lwt_main.run loop there, whilst ocamlfuse executes in the initial thead?
Regarding 2), in single-threaded mode (for the time being), can I just create eg an ('a ref * semaphore) spawn the lwt thread (and block the ocamlfuse thread by waiting on the semaphore), and at the end of the lwt thread, make sure I place the result in the ref and signal the semaphore to indicate that the result is available ?
I hope this description makes sense to someone.