Hi Lutz,
sorry for the postings but im checking/comparing some issues ...
So i have a request...(small one)
Can you perhpas verify for me on your Linux that the Second (fork) example
from the manual 8.9.3 display's this ->
thread 5
thread 4
thread 3
thread 2
thread 1
and not this ->
thread 5
thread 4
thread 3
thread 2
thread 1
thread
If it is displaying the extra "thread" can you also check if there
is perhpas a newlisp process still running after newlisp exited?
And a Second test ->
What does your linux do when you type (exit) when executing the
following from the newlisp commandline ->
>(setq x 0)
>(fork (while (< x 20) (println (inc 'x)) (sleep 1000)))
Does it exit and continue's counting outside newlisp?
You are unable to exit at all from newlisp?
The fork stop completly and newlisp exits?
Nothing happens?
Just currious...
regards, Norman.
The manual entries where most likely made on Linux Mandrake 9.0 or 10.0.
This is what I observe on MacOS X:
> thread 5
thread 4
thread 3
thread 2
thread 1
without the extra 'thread' you are reporting.
On the second test, I still see the forked process thread printing the numbers after exit, but after the number 20 appeared the 'newlisp' entry disappears from the process table, when doing a 'ps' in the MacOS X terminal.
Lutz
Thanks Lutz...
Yes as it is a problem with all Linux version, every linux/unix version handles fork() differently.
(Thats realy realy anoying..that those posix guru's not even are able to create 1 standard..)
Anyway The extra "thread" display happens here on on all BSD fork() flavors like ..
NetBSD / FreeBSD and Debian (not sure is this is bsd releated for fork())
Because there is not a real standard in the behavior of fork() I was wondering is its possible
to replace fork() with spawn*() in newlisp? That way also Windows will have a fork and
spawn is more reliable anyway...
Regards, Norman
I just checked again on MacOS X, FreeBSD and Linux: they are all doing the same thing, but it depends if the code is ecuted in a file, or interactively for the last three statements.
When doing it interactively no extra 'thread' is printed, when doing it from a file you see the extra 'thread' printed, but it is the same on all 3 OS.
Lutz
Your right...yes when doing it from a file its 1 more "thread" printed...
The debian linux stops nicely at the last "thread 1" and i have to press enter.
In OS/2 by the way... I have in both occasions the extra "thread" and it hangs
at the last ""thread" and the fork() or pipe() hangs...... (dont know yet)
When i change (!= x 0) to (>= x 0) it stops nicely at the "thread 1" and I also
have no hanging threads! What could that be??? I think this is a Pipe() problem
and not a fork() problem.. because a normal fork() works fine...but then again
normal pipes work too ;-)
Anyway not a realy big deal but if you have an idea what it could be your welcome
to pop a remark ;-)
Greetings, Norman.
I rewrote the fork/pipe example for the Users Manual entry for 'fork'. This version never prints the spurious 'thread' and does not leave zombies by waiting for the forked processes to finish before exiting:
#!/usr/bin/newlisp
(define (count-down-thread x channel)
(while (!= x 0)
(begin
(write-line (string x) channel)
(dec 'x))))
(define (observer-thread channel)
(do-until (= i "1")
(println "thread " (setq i (read-line channel)))))
(map set '(in out) (pipe))
(set 'observer (fork (observer-thread in)))
(set 'counter (fork (count-down-thread 5 out)))
; avoid zombies
(wait-pid observer)
(wait-pid counter)
(exit)
Lutz
ps: and updated the online manual rev 10
runs like water ;-)