/ Published in: Other
                    
                                        
<p>this example checks that when the context switch occurs in the O'Caml runtime.
compile it with:</p>
<ol>
<li>ocamlc -vmthread -I +threads -I unix unix.cmxa threads.cmxa filename.ml</li>
<li>ocamlc -thread -I +threads -I unix unix.cmxa threads.cmxa filename.ml</li>
<li>ocamlopt -thread -I +threads -I unix unix.cmxa threads.cmxa filename.ml</li>
</ol>
<p>both 1. and 2. terminates, while 3. not (on my OCaml 3.11.1, on Mac OS X).</p>
<p><strong>See also:</strong><a href="http://snipplr.com/view/19509/">http://snipplr.com/view/19509/</a></p>
                compile it with:</p>
<ol>
<li>ocamlc -vmthread -I +threads -I unix unix.cmxa threads.cmxa filename.ml</li>
<li>ocamlc -thread -I +threads -I unix unix.cmxa threads.cmxa filename.ml</li>
<li>ocamlopt -thread -I +threads -I unix unix.cmxa threads.cmxa filename.ml</li>
</ol>
<p>both 1. and 2. terminates, while 3. not (on my OCaml 3.11.1, on Mac OS X).</p>
<p><strong>See also:</strong><a href="http://snipplr.com/view/19509/">http://snipplr.com/view/19509/</a></p>
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
let allocation _ = ignore (String.create 100000)
let r = ref false;;
let rec forever x = allocation (); r:=true; forever x;;
let rec wait _ = if !r then print_string "end.\n" else (allocation (); wait ()) ;;
Thread.create (fun _ -> forever ()) ();;
wait ();; (* blocks forever if we comment out both occurrence of `allocation' *)
Comments
 Subscribe to comments
                    Subscribe to comments
                
                