Le Fri, 27 Sep 2013, Tom Ridge a écrit : > Dear caml-list, > > I have a little program which creates a thread, and then sits in a loop: > > -- > > let f () = > let _ = ignore (print_endline "3") in > let _ = ignore (print_endline "hello") in > let _ = ignore (print_endline "4") in > () > > let main () = > let _ = ignore (print_endline "1") in > let t = Thread.create f () in > (* let _ = Thread.join t in *) > let _ = ignore (print_endline "2") in > while true do > flush stdout; > done > > let _ = main () > > -- > > I compile the program with the following Makefile clause: > > test.byte: test.ml FORCE > ocamlc -o $@ -thread unix.cma threads.cma $< > > When I run the program I get the output: > > 1 > 2 > > and the program then sits in the loop. I was expecting the output from > f to show up as well. If you wait a while, it does. But you have to > wait quite a while. > > What am I doing wrong here? I notice that if I put Thread.yield in the > while loop then f's output gets printed pretty quickly. But why should > the while loop affect scheduling of f's thread? I believe the main lock on the GC can only be released if you allocate or call yield() explicitely. In this case, I suspect that flush does neither, so the loop goes on and the f thread starves. Please let more knowledgeable people correct me if I'm confused. Cheers, -- Simon