caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Thread behaviour
@ 2013-09-27 10:10 Tom Ridge
  2013-09-27 10:22 ` Simon Cruanes
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Tom Ridge @ 2013-09-27 10:10 UTC (permalink / raw)
  To: caml-list

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?

Thanks

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-10-07 14:57 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-27 10:10 [Caml-list] Thread behaviour Tom Ridge
2013-09-27 10:22 ` Simon Cruanes
2013-09-27 10:27 ` Romain Bardou
2013-09-27 10:51   ` Benedikt Grundmann
2013-09-28 19:09     ` Tom Ridge
2013-09-29  7:54       ` Tom Ridge
2013-09-29 12:37         ` Yaron Minsky
2013-09-29 16:25           ` Tom Ridge
2013-09-29 16:46             ` Chet Murthy
2013-09-29 17:18               ` Tom Ridge
2013-09-29 17:47                 ` Chet Murthy
2013-09-30  8:24                   ` Romain Bardou
2013-10-07 14:57                     ` Goswin von Brederlow
2013-09-30  8:16       ` Romain Bardou
2013-10-01  3:32         ` Ivan Gotovchits
2013-10-07 14:49       ` Goswin von Brederlow
2013-09-30  9:18 ` Xavier Leroy
2013-09-30 15:12   ` Tom Ridge
2013-09-30 16:01     ` Török Edwin
2013-09-30 16:56     ` Gabriel Kerneis
2013-09-30 18:18       ` Alain Frisch
2013-10-01  5:01   ` Pierre Chambart
2013-10-01  7:21     ` Gabriel Kerneis
2013-10-02 10:37     ` Wojciech Meyer
2013-10-02 11:52       ` Francois Berenger
2013-10-02 11:58         ` Wojciech Meyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).