9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] Blocking reads on single-threaded Srv-based 9p server?
Date: Fri,  6 Apr 2007 09:52:30 -0400	[thread overview]
Message-ID: <ee9e417a0704060652i6243e9f6y2ae9be6b6fe4e751@mail.gmail.com> (raw)
In-Reply-To: <6ec892cd0704052033r3ae400e2o54bfdf447da9d994@mail.gmail.com>

On 4/5/07, Colin DeVilbiss <cdevilbiss@gmail.com> wrote:
> I'm implementing a 9p server using plan9port.
>
> I'd like one of my files to have "blocking read" or "blocking write"
> behavior: any such call should block until a write occurs on some
> other (non-blocking) file in the same server.

This is perfectly fine to do in a single-threaded server.
You need to implement flush to make sure that clients
don't get hung up indefinitely.

> Is there some reason that I shouldn't implement that in a
> single-threaded server?  The 9p(3) plan9ports manpage suggests that
> only multi-threaded servers should "block" requests by not
> respond()ing to them before returning from the associated service
> routine, and that only multi-threaded servers would need to implement
> flush().

The text is admittedly misleading.
I removed mention of single vs multi-threaded programs.
The real issue is whether requests are always replied to
before returning from the Srv function.  If so, no need
for flush.  If not (which is okay), you need to provide a flush.

> My plan:
>     In my Srv's read() (or write()) routine, if a Req comes in for
> that file and I decide that it should block, I save it off somewhere
> and don't respond() to it.
>     In my write() routine, if a "should unblock any waiters" event
> occurs, go find all of the associated "saved" Req's and respond() to
> them all.
>     Implement a flush() routine that "un-saves" the oldreq and
> responds with "interrupted" (per the manpage).

This is perfectly fine to do in a single-threaded program
and is very common.  Aux/consolefs does it (without lib9p),
and the p9p auth/factotum/log.c implements a one-sided
variant of it for reading from the event log.

> As a side note, I see that none of the 9p filesystems that are
> currently packaged in plan9port are both single-threaded and
> Srv-based.  Is there some reason I don't want to do that here?

P9p's lib9p requires libthread in order to create new processes.
(If someone ever ports p9p to Windows, they'll be happy that
libthread's interface is the only one used to start new programs
instead of widespread use of fork+exec.)

That doesn't mean your program has to be multithreaded.
You can write single-threaded libthread programs.

Russ


  parent reply	other threads:[~2007-04-06 13:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-06  3:33 Colin DeVilbiss
2007-04-06  6:30 ` Kris Maglione
2007-04-06 10:43   ` pedro henrique antunes de oliveira
2007-04-06 10:45     ` pedro henrique antunes de oliveira
2007-04-06 10:58     ` erik quanstrom
2007-04-06 13:52 ` Russ Cox [this message]
2007-04-06 14:01 ` Skip Tavakkolian

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=ee9e417a0704060652i6243e9f6y2ae9be6b6fe4e751@mail.gmail.com \
    --to=rsc@swtch.com \
    --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).