Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Apr 2000 10:14:59 -0700 (PDT)
From:      Archie Cobbs <archie@whistle.com>
To:        freebsd-arch@freebsd.org
Subject:   timeout(9) question
Message-ID:  <200004281714.KAA73019@bubba.whistle.com>

next in thread | raw e-mail | index | archive | help
Question:

Why doesn't the timeout(9) routine call the handler function at
the same spl level that the timeout was registered?

The way it works now, it seems like there's an unavoidable race
condition.

Suppose you have malloc()'d some struct foo and registered a timeout
and your foo_* routines all run at splnet().

Here is the shutdown routine:

  /* called at splnet() */
  void
  foo_shutdown(struct foo *f)
  {
    untimeout(foo_timeout, f, f->callout);
    free(f);
  }

Now consider foo_timeout():

  void
  foo_timeout(void *arg)
  {
    struct foo *f = arg;
    int s;

    s = splnet();
    ..do whatever..
    splx(s);
  }

How do we know that someone didn't call foo_shutdown() between the
time that the timeout handler called foo_timeout() and the splnet()
statement?

This assumes that splsoftclock does not include splnet .. is that correct?
If not, replace splnet with something else not included.

Another thing that bugs me is there's not an easy way to check if
a timeout is already registered, eg:

  extern int timeout_registered(struct callout handle);

-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004281714.KAA73019>