You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have written a small example to test the interaction of Chan.recv and task pools:
moduleT=Domainslib.TaskmoduleC=Domainslib.Chanlet num_domains =Sys.argv.(1) |> int_of_string
let print_mutex =Mutex.create ()letprints=Mutex.lock print_mutex;
print_endline s;
Mutex.unlock print_mutex
let ping =C.make_bounded 1let pong =C.make_bounded 1let pang =C.make_unbounded ()letrun_asyncnamep()=letrec f() : unit =C.recv p;
print name;
C.send pang ();
f ()in
f ()let()=let pool =T.setup_pool ~num_domains:(num_domains -1) ()inT.run pool (fun_ ->
let _ =T.async pool (run_async "A" ping) inlet _ =T.async pool (run_async "B" pong) inwhiletruedoC.send ping ();
C.send pong ();
C.recv pang
done
);
T.teardown_pool pool
The output of the program above depends on the input parameter num_domains. When called with 1, the program immediately blocks. When called with 2, it outputs "A" "A" and then blocks. If called with >= 3 it runs indefinitely, as expected. It seems to me, that a call to Chan.recv on an empty channel effectively blocks and removes the current domain from the pool.
Is that the expected behaviour?
The text was updated successfully, but these errors were encountered:
I haven't gone through all the details, but I believe the problem is that Chan uses Stdlib Mutex and Condition to block. The problem with those is that they prevent other fibers (spawned with async) from running. Ideally your example would be able to run with just one domain (like the example I posted on discuss using Kcas). In the future, perhaps, domainslib internals get rewritten using something like Picos and everything will just work™️. 😄
I have written a small example to test the interaction of Chan.recv and task pools:
The output of the program above depends on the input parameter num_domains. When called with 1, the program immediately blocks. When called with 2, it outputs "A" "A" and then blocks. If called with >= 3 it runs indefinitely, as expected. It seems to me, that a call to Chan.recv on an empty channel effectively blocks and removes the current domain from the pool.
Is that the expected behaviour?
The text was updated successfully, but these errors were encountered: