From owner-freebsd-threads@FreeBSD.ORG Thu Feb 20 03:39:20 2014 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A715059E; Thu, 20 Feb 2014 03:39:20 +0000 (UTC) Received: from alogt.com (alogt.com [69.36.191.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7BD9F1850; Thu, 20 Feb 2014 03:39:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=alogt.com; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date; bh=yre7YymE+a8m2Vg/eil5/04v5d3NrHpt+xAzof75zV4=; b=m7k/cvOPFziIj1Lq9k6QCG88JmE3SoZZa0j3bp0ekiSkvjkzPWPsbnNdvL6ObZXEoCCu05h7iR95cC0PGNUbYIUqKQME1VGwlDON7w9f/W45vCLQW48jFruqbBix4yqjLPJCnsspyhJdCOSdBvORPnA3RGvhqKk1XBG+pGEXq3E=; Received: from [39.199.31.111] (port=10635 helo=X220.alogt.com) by sl-508-2.slc.westdc.net with esmtpsa (SSLv3:DHE-RSA-AES128-SHA:128) (Exim 4.82) (envelope-from ) id 1WGKTd-003x4N-Ri; Wed, 19 Feb 2014 20:39:11 -0700 Date: Thu, 20 Feb 2014 11:39:02 +0800 From: Erich Dollansky To: Andre Albsmeier Subject: Re: pthread programming eats up resources (My or FreeBSD's fault?) Message-ID: <20140220113902.63e97b00@X220.alogt.com> In-Reply-To: <20140219162441.GA3564@schlappy> References: <20140218180646.GA67861@schlappy> <20140219144728.GA3036@schlappy> <20140219230824.0f2ba24b@X220.alogt.com> <5304CE2C.1060305@mu.org> <20140219162441.GA3564@schlappy> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.22; amd64-portbld-freebsd10.0) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sl-508-2.slc.westdc.net X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - alogt.com X-Get-Message-Sender-Via: sl-508-2.slc.westdc.net: authenticated_id: erichsfreebsdlist@alogt.com X-Source: X-Source-Args: X-Source-Dir: Cc: freebsd-hackers@freebsd.org, freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Feb 2014 03:39:20 -0000 Hi, On Wed, 19 Feb 2014 17:24:41 +0100 Andre Albsmeier wrote: I am now running this program: > #include > #include > #include > > #define THREADS 1000 > > int c = 0; > pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; > > void* mythread( void* arg ) > { > pthread_mutex_lock( &mtx ); > c--; > pthread_mutex_unlock( &mtx ); > > return NULL; > } > > int main( int argc, const char* const argv[] ) > { > pthread_t pthr; > int i; > > while( 1 ) { > > pthread_mutex_lock( &mtx ); > c += THREADS; > pthread_mutex_unlock( &mtx ); > > for( i=THREADS; i; i-- ) > if( pthread_create( &pthr, NULL, mythread, NULL ) != 0 ) > fprintf( stderr, "pthread_create\n" ); > else > pthread_detach( pthr ); > > pthread_mutex_lock( &mtx ); > fprintf( stderr, "%d:", c ); > pthread_mutex_unlock( &mtx ); > > usleep( 25000 ); > > pthread_mutex_lock( &mtx ); > fprintf( stderr, "%d ", c ); > pthread_mutex_unlock( &mtx ); > } > } It runs on an i7 with two cores plus two hyper threads. The machine has 8GB of RAM and 16GB of Swap. The resident part of the program stays below 8GB (what wonder) but the rest is swapped out. I run this program on 10.0 from some 2 weeks ago. As already said, it looks like there stays some memory left after a thread terminates. To say something positive, the program really cleaned the memory. Erich