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: David MENTRE <dmentre@l...>
Subject: Re: [Caml-list] Blocked thread ???
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