From mboxrd@z Thu Jan 1 00:00:00 1970 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> Topicbox-Message-UUID: 9533e030-eacd-11e9-9e20-41e7f4b1d025 > 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