I was experimenting few things with Eio Fibers and Affect Fibers.
let main () =
let comp () =
Eio_linux.run ( fun _env ->
ignore (Fiber.run (fun () ->
Eio.Std.Switch.run @@ fun sw ->
(
Eio.Fiber.fork ~sw (
fun () ->
printf "\nEio Fiber 1 %!"
);
(* printf "\nReaching in between two threads%!";*)
let _ = Fiber.spawn (
fun () ->
printf "\nAffect Fiber 1 %!"
) in ();
Eio.Fiber.fork ~sw (
fun () ->
printf "\nEio Fiber 2 %!"
);
)
)
)
)
in
match_with comp ()
{ retc = (fun () -> ());
exnc = (function
| Exit -> ()
);
effc = fun (type a) (e : a Effect.t) ->
match e with
| _ -> None
}
let _ = main ()
When I ran the above program, I was expecting the output to be
Eio Fiber 1
Affect Fiber 1
Eio Fiber 2
Instead, I got the output as
Eio Fiber 1
Eio Fiber 2
Affect Fiber 1
With all permutations of Affect and Eio Fibers, I found that Affect fibers are always printed after Eio fibers. Affect fibers will not take action until all Eio fibers are executed. To check it further, I added a few print statements in Affect’s spawn functionality to understand its flow. From its output, it can be seen that control definitely reaches to spawn function, but it does not execute the input f at that time.
As a developer, I want to maintain sequentiality in my application. I want fibers to execute one after another. How can I achieve this in the above program? Which approach should I take to tackle this problem? I want to understand why Eio Fibers are taking priority over Affect fibers.