From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <1c0a9bd9476375c4d3b683c30ec5b683@terzarima.net> To: 9fans@cse.psu.edu Subject: Re: [9fans] stack reclamation on Unix using clone, rfork_thread, etc. From: Charles Forsyth Date: Fri, 4 Jun 2004 17:43:06 +0100 In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-guclzvbbrdsbtkxfuhshwkxzbx" Topicbox-Message-UUID: 95423554-eacd-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-guclzvbbrdsbtkxfuhshwkxzbx Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit >>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! --upas-guclzvbbrdsbtkxfuhshwkxzbx Content-Type: message/rfc822 Content-Disposition: inline Received: from mail.cse.psu.edu ([130.203.4.6]) by lavoro; Fri Jun 4 17:40:20 BST 2004 Received: from psuvax1.cse.psu.edu (localhost [127.0.0.1]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id 271CB19E77 for ; Fri, 4 Jun 2004 12:39:12 -0400 (EDT) X-Original-To: 9fans@cse.psu.edu Delivered-To: 9fans@cse.psu.edu Received: from localhost (neuromancer.cse.psu.edu [130.203.4.2]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id 4367D19C33 for <9fans@cse.psu.edu>; Fri, 4 Jun 2004 12:39:00 -0400 (EDT) Received: from mail.cse.psu.edu ([130.203.4.6]) by localhost (neuromancer [130.203.4.2]) (amavisd-new, port 10024) with LMTP id 15155-01-19 for <9fans@cse.psu.edu>; Fri, 4 Jun 2004 12:38:57 -0400 (EDT) Received: from mproxy.gmail.com (mproxy.gmail.com [216.239.56.250]) by mail.cse.psu.edu (CSE Mail Server) with SMTP id C3D3519C01 for <9fans@cse.psu.edu>; Fri, 4 Jun 2004 12:38:56 -0400 (EDT) Received: by mproxy.gmail.com with SMTP id u22so82563cwc for <9fans@cse.psu.edu>; Fri, 04 Jun 2004 09:38:56 -0700 (PDT) Received: by 10.11.98.15 with SMTP id v15mr3173cwb; Fri, 04 Jun 2004 09:38:56 -0700 (PDT) Message-ID: Date: Fri, 4 Jun 2004 12:38:56 -0400 From: Russ Cox 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. In-Reply-To: <6.1.1.1.0.20040604175442.021d8420@pop.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <200406041533.i54FXNm29967@plg2.math.uwaterloo.ca> <6.1.1.1.0.20040604175442.021d8420@pop.free.fr> X-Virus-Scanned: by amavisd-new at cse.psu.edu X-BeenThere: 9fans@cse.psu.edu X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> List-Id: Fans of the OS Plan 9 from Bell Labs <9fans.cse.psu.edu> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: 9fans-bounces+forsyth=terzarima.net@cse.psu.edu Errors-To: 9fans-bounces+forsyth=terzarima.net@cse.psu.edu > 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 --upas-guclzvbbrdsbtkxfuhshwkxzbx--