9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: David Presotto <presotto@closedmind.org>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Fork: useless and painful?
Date: Thu, 10 Jul 2003 12:47:14 -0400	[thread overview]
Message-ID: <5b68877f993232fb23394caf30309e12@plan9.bell-labs.com> (raw)
In-Reply-To: <212c59d55eb25badcbc00c9fe4121065@vitanuova.com>

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

That's why we have libthread with its threadcreate/proccreate/procexec.
I've been moving stuff over to windows and just kept the libthread
interface.

It's amazing how awkward win32 makes all of the same.  Every
process control call turns into a handful of calls, each with
a dozen params.

[-- Attachment #2: Type: message/rfc822, Size: 3652 bytes --]

From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Fork: useless and painful?
Date: Thu, 10 Jul 2003 15:59:34 +0100
Message-ID: <212c59d55eb25badcbc00c9fe4121065@vitanuova.com>

> I'm hearing the claim that fork is "useless and painful" (from an IBM K42
> guy).
>
> Maybe it's just me, but I've always liked fork.

fork's kinda nice, but can be confusing.
plan9 has really moved away from fork for multithreaded programs
towards the "spawn" style proccreate.  (rfork for other resource
attributes is quite different, i think)

a day or so ago, i had occasion to write the following code:

	int
	mpipe(void)
	{
		char buf[BUFSIZE];
		int n, p[2];

		pipe(p);
		if(fork() == 0){
			if(fork() == 0){
				close(p[1]);
				return p[0];
			}
			close(p[0]);
			while((n = read(0, buf, sizeof(buf))) > 0)
				write(p[1], buf, n);
			exits(nil);
		}
		close(p[0]);
		while((n = read(p[1], buf, sizeof(buf))) > 0)
			write(1, buf, n);
		exits(nil);
	}

there's nothing particularly complicated going on and i don't *think*
the implementation is particularly obtuse, but i don't find reading
that code straightforward.

here's a different structure to the same end:

	int
	mpipe(void)
	{
		int p[2];
		pipe(p);
		spawn copy(0, p[1]);
		spawn copy(p[1], 1);
		return p[0];
	}

	void
	copy(int fd0, int fd1)
	{
		char buf[BUFSIZE];
		int n;
		while((n = read(fd0, buf, sizeof(buf))) > 0)
			write(fd1, buf, n);
	}

ok, i cheated, assuming that C has been given a "spawn" statement
similar to Limbo's.  nonetheless, i think the structure itself is
clearer, and the meaning of the code more transparent - no possibility
of accidentally duplicating the *caller* of mpipe...

given that forking a process in plan 9, unlike unix, is not synonymous
with forking its file descriptors, surely the only real reason to
prefer it is that the call fits more nicely into the C syntax; one
doesn't have to bypass typechecking in order to pass arguments to a
new process.

how often does anyone do anything with fork that could not be done at
least as easily with spawn?

  reply	other threads:[~2003-07-10 16:47 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-09 18:19 ron minnich
2003-07-09 18:26 ` Scott Schwartz
2003-07-09 19:39   ` boyd, rounin
2003-07-09 19:45     ` Dan Cross
2003-07-09 20:05       ` Derek Fawcus
2003-07-09 20:09         ` andrey mirtchovski
2003-07-09 20:34           ` Derek Fawcus
2003-07-09 21:08           ` Vincent van Gelderen
2003-07-09 20:31             ` Sam
2003-07-09 21:35               ` boyd, rounin
2003-07-09 22:04               ` andrey mirtchovski
2003-07-09 22:31                 ` boyd, rounin
2003-07-10  1:11             ` ron minnich
2003-07-10  1:17               ` boyd, rounin
2003-07-09 20:14         ` boyd, rounin
2003-07-09 20:31           ` Dan Cross
2003-07-09 20:25         ` Dan Cross
2003-07-10  6:10         ` Mike Haertel
2003-07-10  6:59           ` boyd, rounin
2003-07-09 22:01       ` Geoff Collyer
2003-07-09 22:28         ` boyd, rounin
2003-07-09 22:54           ` OT lunix rants (Was: [9fans] Fork: useless and painful?) andrey mirtchovski
2003-07-09 23:26             ` boyd, rounin
2003-07-10  6:15         ` [9fans] Fork: useless and painful? Mike Haertel
2003-07-10  6:51           ` Geoff Collyer
2003-07-10  7:22             ` boyd, rounin
2003-07-10  8:59               ` Derek Fawcus
2003-07-11 11:24             ` Alexis S. L. Carvalho
2003-07-09 18:36 ` Dan Cross
2003-07-09 19:35 ` boyd, rounin
2003-07-10 14:59 ` rog
2003-07-10 16:47   ` David Presotto [this message]
2003-07-10 19:36     ` Stephen Wynne
2003-07-10 19:57       ` boyd, rounin
2003-07-10 20:06         ` Stephen Wynne
2003-07-10 20:16           ` boyd, rounin
2003-07-11  0:05         ` David Presotto
2003-07-11 15:01           ` ron minnich
2003-07-14  8:51           ` John Kodis
2003-07-14 13:24             ` Lucio De Re
2003-07-14 13:58               ` boyd, rounin
2003-07-14 15:20               ` ron minnich
2003-07-11  2:01 Andrew Simmons
2003-07-11  2:17 ` David Presotto
2003-07-11  2:29   ` boyd, rounin
     [not found]   ` <presotto@closedmind.org>
2003-07-13 19:44     ` Andrew Lynch
2003-07-11  2:32 ` boyd, rounin
2003-07-11 10:59 ` matt
2003-07-11  4:46 Andrew Simmons
2003-07-11  5:14 ` boyd, rounin
2003-07-11  6:21   ` northern snowfall
2003-07-11  5:43     ` boyd, rounin
2003-07-11  8:52   ` Douglas A. Gwyn
2003-07-11 13:27   ` D. Brownlee
2003-07-31 21:07 Joel Salomon
2003-07-31 22:19 ` Dan Cross
2003-08-01  3:00 ` Joel Salomon
2003-08-01 14:42 ` Jack Johnson
2003-08-01 22:26   ` Jim Choate
2003-08-02  8:05     ` Jack Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b68877f993232fb23394caf30309e12@plan9.bell-labs.com \
    --to=presotto@closedmind.org \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).