caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Blocked thread ???
@ 2004-03-26 10:21 Christophe Raffalli
  2004-03-26 10:27 ` [Caml-list] " Christophe Raffalli
  2004-03-26 20:04 ` [Caml-list] " David MENTRE
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe Raffalli @ 2004-03-26 10:21 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 2144 bytes --]


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
---------------------------------------------

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

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

end of thread, other threads:[~2004-03-26 20:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-26 10:21 [Caml-list] Blocked thread ??? Christophe Raffalli
2004-03-26 10:27 ` [Caml-list] " Christophe Raffalli
2004-03-26 20:04 ` [Caml-list] " David MENTRE

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).