9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Axel Belinfante <Axel.Belinfante@cs.utwente.nl>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] thread confusion
Date: Wed, 21 Sep 2005 22:25:38 +0200	[thread overview]
Message-ID: <200509212025.j8LKPdr29497@demeter.cs.utwente.nl> (raw)
In-Reply-To: Your message of "Wed, 21 Sep 2005 11:42:42 -0400." <ee9e417a0509210842637ec1e2@mail.gmail.com>

> But leave the proc alone and figure out the pipe close
> bug instead.  The most likely problem is that you haven't
> actually closed the other side of the pipe completely.
> For example, maybe you have forked a child who inherited
> a copy of that fd, and that child is holding the pipe up.

the problem seems to be that at both ends of the pipe
a read is 'hanging'.
(one from tlsClient, and one from my own pipe reader proc)
If I in this situation close (both ends of) the pipe,
it doesn't work.

I have tried to mimic the situation in a small
test program, and there I found:

if I first close one randomly chosen end of the pipe,
and then do a zero-length write at the other end and
then close that end, it works.
It also works if I first close one end of the pipe,
and then do the zero-length write and close at the
other end.

is this a correct procedure, or would another be preferred?




> Programming with notes or signals is asking for trouble.

I do use a timer, by having a proc that repeatedly sleeps
and decrements a counter, and when the counter reaches
zero it sends a (nil) timeout message on a channel.
in alts I not only wait for the io channels but
also for the timer timeout channel.

the question is how to start and reset the timer.
I have been thinking about using channels for that
too, but that seems deadlock prone: how to avoid
the case where I want to send a reset message to
the timer when the timer wants to send an expiration
message to me?
could I work around that by having a timer thread
in the same process with the main thread(s) that use it,
and a separate clock proc (process) that does regular
sleeps to generate regular tick messages?
the timer thread forever does an alt to
 - receive timer start message (contains timer and timeout value)
 - receive timer reset message (contains timer)
 - receive tick message, triggers decrement of counters
   and sending of timeout message if counter reaches zero
the clock proc forever sleeps and sends tick messages
to the timer thread.


Axel.


  reply	other threads:[~2005-09-21 20:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-21 14:44 Fco. J. Ballesteros
2005-09-21 15:05 ` Axel Belinfante
2005-09-21 15:42   ` Russ Cox
2005-09-21 20:25     ` Axel Belinfante [this message]
2005-09-21 20:32       ` Axel Belinfante
2005-09-21 20:37       ` Russ Cox
2005-09-21 22:34         ` Axel Belinfante
2005-09-21 22:44           ` Russ Cox
2005-09-26 18:40       ` rog
2005-09-26 18:52         ` Russ Cox
2005-09-26 19:20           ` rog
2005-09-27 10:12         ` Axel Belinfante
  -- strict thread matches above, loose matches on Subject: below --
2005-09-21 15:48 Fco. J. Ballesteros
2005-09-21 13:53 Fco. J. Ballesteros
2005-09-21 14:32 ` Axel Belinfante
2005-09-21 13:25 Axel Belinfante

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=200509212025.j8LKPdr29497@demeter.cs.utwente.nl \
    --to=axel.belinfante@cs.utwente.nl \
    --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).