From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 4 Jun 2004 11:33:23 -0400 From: Richard C Bilson Message-Id: <200406041533.i54FXNm29967@plg2.math.uwaterloo.ca> To: 9fans@cse.psu.edu Subject: Re: [9fans] stack reclamation on Unix using clone, rfork_thread, etc. Topicbox-Message-UUID: 95124588-eacd-11e9-9e20-41e7f4b1d025 > From 9fans-bounces+rcbilson=plg.uwaterloo.ca@cse.psu.edu Fri Jun 4 11:19:57 2004 > > I would associate each stack segment to an 'address space' structure > shared by each shared-memory process. > When the reference counter of this structure goes to zero, I would > free all the segment 'associated' to this structure (and free the structure > :) ). Yes, but what thread does the free? You can't free your own stack, and how does any other thread know to do it for you? This is a pain, and a pain that I have felt myself. Of course, it's easy if there is some kind of termination synchronization, and the thread that waits is responsible for cleaning up after the thread that finishes. But I assume that Russ is trying to solve the problem in the general case. As far as I know, the new pthreads library on Linux uses a technique very similar to the one that Russ describes, with the additional optimization of re-using stacks if possible. In fact, I'm not sure if they ever free stacks -- just keep them around in case a new thread needs one. The old linuxthreads library used a "manager thread" to do the reaping (among other things), which isn't particularly nice or efficient.