From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 4 Jun 2004 12:44:50 -0400 From: Richard C Bilson Message-Id: <200406041644.i54Giob06093@plg2.math.uwaterloo.ca> To: 9fans@cse.psu.edu Subject: Re: [9fans] stack reclamation on Unix using clone, rfork_thread, etc. Topicbox-Message-UUID: 953e3b7a-eacd-11e9-9e20-41e7f4b1d025 > From: Philippe Anel Fri Jun 4 12:23:49 2004 > > 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); > } > > ------------------------------------------------------------------------------ > > It would free the stack of the previous exited thread. This isn't actually so different from what Russ describes -- you're just keeping a separate free list, rather than setting a per-thread flag in some global list of all threads. Note that you have to be very careful about race conditions -- your stack could disappear immediately after the call to unlock, which means that you'd better be done all you need to do at that point, except for calling _exit (and even that is problematic).