From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 28 22:41:20 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AB5DD16A407 for ; Tue, 28 Nov 2006 22:41:20 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout4.cac.washington.edu (mxout4.cac.washington.edu [140.142.33.19]) by mx1.FreeBSD.org (Postfix) with ESMTP id 85D1343CB7 for ; Tue, 28 Nov 2006 22:40:46 +0000 (GMT) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.32.139]) by mxout4.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW06.09) with ESMTP id kASMepFY002570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 28 Nov 2006 14:40:51 -0800 X-Auth-Received: from [128.208.5.99] (nilakantha.cs.washington.edu [128.208.5.99]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW06.09) with ESMTP id kASMepMh009367 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 28 Nov 2006 14:40:51 -0800 Message-ID: <456CBB09.10804@u.washington.edu> Date: Tue, 28 Nov 2006 14:41:13 -0800 From: Garrett Cooper User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org References: <456CAB12.9070507@u.washington.edu> <200611282302.08439.pieter@degoeje.nl> In-Reply-To: <200611282302.08439.pieter@degoeje.nl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.2.2.285561, Antispam-Engine: 2.5.0.283055, Antispam-Data: 2006.11.28.142933 X-Uwash-Spam: Gauge=XI, Probability=11%, Report='ADULT_MED_1 1, __ADULT_ANY 0, __ADULT_PHRASE_8_LO 0, __CP_NAME_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' Subject: Re: pthreads : questions about concurrency and lifetime X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Nov 2006 22:41:20 -0000 Pieter de Goeje wrote: > On Tuesday 28 November 2006 22:33, Garrett Cooper wrote: > >> Hello once again, >> Just wondering about pthreads now. I know that the lifetime (scope) >> of a regular procedural function in C is simple.. it's from the top of >> the function body to the bottom of the function body (assuming no >> infinite loops are injected). Example: >> >> (void*) function(void*) {/* lifetime of function is here. */ } >> >> However looking over pthread(3), there are a number of different >> functions for killing threads and exiting child threads, in order >> terminate child threads (and maybe to get back to the main thread of >> execution in a program). >> >> So my question is, once the end of a function body is reached that was >> made using pthread_create(), does the thread exit and 'destroy' itself >> or do I need to do 'manual' cleanup, i.e. run pthread_detach(3), >> pthread_exit(3), or pthread_kill(3)? >> > > There are three ways to cleanup a thread: > 1) pthread_detach(3) > 2) pthread_join(3) > 3) creating a thread with PTHREAD_CREATE_DETACHED attribute set, see > pthread_attr_setdetachstate(3) > > Calling pthread_detach(3) directly after you created the thread is an easy way > to create an "uncontrolled" thread. Effectively the same as #3. The thread > will cleanup automatically after the thread function returns. > > -- Pieter de Goeje > So that means no, after a function's definition is reached the thread/resources stay in a semi-'alive' (maybe 'zombified') state?, or does the kernel cleanup / reclaim all of the resources tied up with the thread? -Garrett