From 1eef212a3e844e6b3e4eb9f2e83446b83934679b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 4 Sep 2025 15:32:32 -0400 Subject: [PATCH] more sanity checks --- src/lwt/moonpool_lwt.ml | 4 +++- src/lwt/moonpool_lwt.mli | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lwt/moonpool_lwt.ml b/src/lwt/moonpool_lwt.ml index b563fa52..9895ad30 100644 --- a/src/lwt/moonpool_lwt.ml +++ b/src/lwt/moonpool_lwt.ml @@ -34,7 +34,7 @@ module Scheduler_state = struct tasks = Queue.create (); actions_from_other_threads = Queue.create (); mutex = Mutex.create (); - thread = Thread.self () |> Thread.id; + thread = -1; closed = false; as_runner = Moonpool.Runner.dummy; enter_hook = None; @@ -157,6 +157,8 @@ let await_lwt (fut : _ Lwt.t) = ) let lwt_of_fut (fut : 'a M.Fut.t) : 'a Lwt.t = + if not (Ops.on_lwt_thread_ Scheduler_state.st) then + failwith "lwt_of_fut: not on the lwt thread"; let lwt_fut, lwt_prom = Lwt.wait () in (* in lwt thread, resolve [lwt_fut] *) diff --git a/src/lwt/moonpool_lwt.mli b/src/lwt/moonpool_lwt.mli index c8ca9485..7696246b 100644 --- a/src/lwt/moonpool_lwt.mli +++ b/src/lwt/moonpool_lwt.mli @@ -18,7 +18,8 @@ val fut_of_lwt : 'a Lwt.t -> 'a Moonpool.Fut.t val lwt_of_fut : 'a Moonpool.Fut.t -> 'a Lwt.t (** [lwt_of_fut fut] makes a lwt future that completes when [fut] does. This must be called from the Lwt thread, and the result must always be used only - from inside the Lwt thread. *) + from inside the Lwt thread. + @raise Failure if not run from the lwt thread. *) (** {2 Helpers on the moonpool side} *)