9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Charles Forsyth <forsyth@terzarima.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] stack reclamation on Unix using clone, rfork_thread, etc.
Date: Fri,  4 Jun 2004 17:43:06 +0100	[thread overview]
Message-ID: <1c0a9bd9476375c4d3b683c30ec5b683@terzarima.net> (raw)
In-Reply-To: <ee9e417a040604093860e7fcf5@mail.gmail.com>

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

>>the inferno version posted by charles fixes this.

actually i sent that privately, but it's fairly obvious (once you know
the dangers).  the mess in that one is that it needs assembly language in order
to have precise control over access to the stack and to allow
an INT $SYS_exit or whatever to be made without using the (user) stack,
so that you need to do the raw INT yourself, not call _exit,
after unlocking the global stack allocation Lock.  void unlockandexit(Lock*).
ugh.  it also can't simply free() the stack, but can only recycle it,
though you could fix that one by queueing the stack for freeing
by the next stackalloc once it's past the global lock.

now, go hug a TLB!

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

From: Russ Cox <russcox@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] stack reclamation on Unix using clone, rfork_thread, etc.
Date: Fri, 4 Jun 2004 12:38:56 -0400
Message-ID: <ee9e417a040604093860e7fcf5@mail.gmail.com>

> void
> exit_thread()
>   {
>          struct segment * s;
> 
>          lock(&addrspace);
>          for (s = addrspace.tofree; s; s = s->next)
>                  free(s->addr);
>          if (--refcount) {
>                  s = find_segment_from_id(get_my_thread_id());
>                  list_remove(s);
>                  list_add(tofree, s);
>                  unlock(&addrspace);
>          }
> }

this isn't safe because you keep using the stack
after you unlock &addrspace, so someone else
might come along and free it out from under you
before you manage to exit.  the inferno version
posted by charles fixes this.

unfortunately, i'm trying not to assume that all the threads
will exit with my exit function, so this approach isn't
really an option.

russ

  reply	other threads:[~2004-06-04 16:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-04 15:33 Richard C Bilson
2004-06-04 15:53 ` Russ Cox
2004-06-04 18:43   ` boyd, rounin
2004-06-04 16:22 ` Philippe Anel
2004-06-04 16:24   ` Philippe Anel
2004-06-04 16:38   ` Russ Cox
2004-06-04 16:43     ` Charles Forsyth [this message]
2004-06-04 19:02   ` boyd, rounin
2004-06-04 18:35 ` boyd, rounin
  -- strict thread matches above, loose matches on Subject: below --
2004-06-04 16:44 Richard C Bilson
2004-06-04 14:39 Russ Cox
2004-06-04 15:20 ` Philippe Anel
2004-06-04 15:23   ` Philippe Anel
2004-06-04 18:30 ` boyd, rounin
2004-06-04 18:38   ` Russ Cox

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=1c0a9bd9476375c4d3b683c30ec5b683@terzarima.net \
    --to=forsyth@terzarima.net \
    --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).