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

* [Caml-list] Re: Blocked thread ???
  2004-03-26 10:21 [Caml-list] Blocked thread ??? Christophe Raffalli
@ 2004-03-26 10:27 ` Christophe Raffalli
  2004-03-26 20:04 ` [Caml-list] " David MENTRE
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Raffalli @ 2004-03-26 10:27 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

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

Morevoer, using Thread.wait_pid instead of Unix.pid does nothing ...

And sometimes the program segfaults :-(


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

* Re: [Caml-list] Blocked thread ???
  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 ` David MENTRE
  1 sibling, 0 replies; 3+ messages in thread
From: David MENTRE @ 2004-03-26 20:04 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

Hello Christophe,

Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr> writes:

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

Are you sure it is not related to scheduling issues? On following
slightly modified version of your program, I have added a "nice -n20"
call and both codes seem to execute concurrently. But I agree with you
that this behavior is quite strange: with "nice -n0" (i.e. normal
priority) the calling process is stopped. 

Is your initial thread also doing CPU intensive job? Linux kernel 2.4 is
known not to be very responsive in case a program is using all the
CPU. This is one of the improvement in kernel 2.6. But I might be
totally wrong. :)

let _ =
  let command = "/usr/bin/nice" in
  let command_args =
    [|
      "/usr/bin/nice";
      "-n20";
      "/usr/bin/factor";
      "12345678909999999999"; 
    |]
  in
  let f () =
    print_string ("Calling POVRay: "^command);
    print_newline ();
    let pid = Unix.fork() in
    let status =
      if pid < 0 then (
        print_string "error while forking";
        print_newline ();
        flush stdout
       );
      if pid = 0 then begin
	Unix.execvp command command_args;
	Unix.WEXITED(1)
      end else  begin
	snd (Thread.wait_pid pid)
      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 produced file");
      print_newline ()
    end;
    flush stdout
  in
  let t = Thread.create f () in
  Printf.printf ("doing other computation in initial thread");
  for i = 1 to 2000 do Printf.printf "%i\n" i; flush stdout done;
  Printf.printf ("computation done in initial thread");
  Thread.join t
  

61
Calling POVRay: /usr/bin/nice
62
[...]
1296
12345678909999999999: 3 3 3 3 79 1929313784966401
 
 
Calling POVRay on file produced file
1297


Yours,
d.
-- 
 David Mentré <dmentre@linux-france.org>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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