Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Blocked thread ???
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe Raffalli <Christophe.Raffalli@u...>
Subject: [Caml-list] Blocked thread ???

I use the piece of code at the end of the mail to launch an external 
command from a thread. The problem is that despite the fact execpv is 
called from a newly created thread, the original thread does not get any 
CPU until the
command stop computing (but the command is still running waiting for a 
click).

I tried to use Sys.command and also Sys.command "... &" with no extra 
thread creation, but the same happend. I think I am missing somthing ...

I am using ocaml 3.07pl2 and should not have to use the obsolete 
threadUnix ...

Remark: the thread excuting the piece of code below is itself a 
secondary thread (not the main thread). I do not know if this is important.

   let command = "povray" in
   let command_args =
     [|
       "povray";
       "+SP8"; "+FN8"; "+P";
       Printf.sprintf "+A%f" !pov_aliasing;
       Printf.sprintf "+W%d" pixels;
       Printf.sprintf "+H%d" (int_of_float (ratio *. (float) pixels));
       Printf.sprintf "+O%s" out_filename;
       in_filename
     |]
   in
   let f () =
     print_string ("Calling POVRay: "^command);
     print_newline ();
     let pid = Unix.fork() in
     let status =
       if pid = 0 then begin
	Thread.yield ();
	Unix.execvp command command_args;
	Unix.WEXITED(1)
       end else  begin
	Thread.yield ();
	snd (Unix.wait())
       end;
     in
     if status <> Unix.WEXITED(0) then begin
       print_string ("execution of \""^command^"\" failed.");
       print_newline ();
     end else begin
       print_newline ();
       print_newline ();
       Printf.printf ("Calling POVRay on file %s produced file %s")
	in_filename out_filename;
       print_newline ()
     end
   in
   ignore (Thread.create f ())

-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature
---------------------------------------------