"Joe Wood" <joew@ndirect.co.uk> has essentially given the correct
answer to David, I think:
> Date: Fri, 26 Mar 2004 19:52:48 -0000
[JW]
> If you fork a process, you will create a new process with its own memory.
> Any OS would get very confused otherwise; for example how would you control
> file access etc.?
That is what the unix/linux system call fork does (as invoked by
sys_fork).
vfork (as invoked by sys_vfork) is for the special case where you
don't want the new process to be a copy of the original, but an
execution of something else. Then, as an efficiency hack, the new
process created by vfork is almost entirely just the old process.
This 'virtual copy' should should immediately be replaced by a new
process created using the exec system call (as invoked by
sysexecute).
On modern unix/linux systems, 'fork' does not immediately create a
whole new completely separate process, but uses copy-on-write to
make a copy only if something is changed in the new process. So the
efficiency advantage of vfork is reduced or eliminated.
Either way the end result is two processes with different control
stacks, memories, different address spaces, etc.
So there is no way they can share variables. (I.e. threads with
shared programmer variables cannot be implemented as separate
unix/linux processes.)
The two processes produced by fork/vfork can communicate via files,
pipes, sockets or files mapped into memory (See man mmap). On VMS
there are things called mailboxes I believe.
There is more information about threads and design options here:
http://people.redhat.com/drepper/nptl-design.pdf
http://www.redhat.com/partners/pdf/POSIX_Linux_Threading.pdf
At present, if you implement threads using pop11's lightweight
processes (using consproc, etc.) then you can have shared global
variables etc. but
(a) you have to do your own scheduling, as explained previously
(b) you can't gain any benefit from multiple CPUs (SMP)
I have not studied the recent thread developments mentioned above,
but I suspect that it would not be a trivial matter for poplog/pop11
to take advantage of any new low-level threading mechanisms designed
for use in languages with very different functionality allowing
compilers to make more inferences at compile-time (e.g. C, C++ or
Java).
> This begs the question what are you really trying to do? Why do you want
> multiple threads? Yes, there can be good reasons, but on a single CPU this
> is not always the case.
>
> I did write (a few years ago) a pop-11 section to enable communications
> between forked processes via pipes, pipe-manager.p. You can have a copy, but
> you will a few other files to understand how to use it. It was useful
> because I wanted to supply input to a exe file for which I had no source,
> and read back the replies.
If you ever feel like making it generally available, create a
directory tree containing whatever subset of
auto, lib, src, include, data, teach, help, ref, doc
libraries you wish to provide. Then it can be put into a tar
file along with an additional 'startup' file extending search
lists to include the above directories. I normally do that simply
by copying and editing an existing startup file e.g.
http://www.cs.bham.ac.uk/research/poplog/rclib/rclib.p
[The creation of startup files should be automated. Maybe one
day...]
The package can then be made available at Poplog sites as a gzipped
tar file including the startup file, which can be linked to a
pre-existing lib/ directory to simplify access (e.g. via 'uses').
Aaron
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html
|