From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 19 15:53:05 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1C820144; Wed, 19 Feb 2014 15:53:05 +0000 (UTC) Received: from mail-qc0-x22f.google.com (mail-qc0-x22f.google.com [IPv6:2607:f8b0:400d:c01::22f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B49151569; Wed, 19 Feb 2014 15:53:04 +0000 (UTC) Received: by mail-qc0-f175.google.com with SMTP id x13so758901qcv.6 for ; Wed, 19 Feb 2014 07:53:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=LojqmoGwSaJXOshXdbS7hU+6Q+ODcxN2ZcE1RtagsTM=; b=UA/d/woNjPZunaVim3CtOU9KF3hxcZxNdT+5WnPPbpbKicAtI09MjH0sFDsLzM9J6k LR2UUVhgHBte7RydRAaQ/k5oPLjZkuLru9tOIsGLeVk30nVext6nnyLEapaxk4stCFwk CczCcAgkPcPkT6veP6sVbap1qK2Fihk5OJvUwgvUqyIlAMcQA94JZ1ch0uFm2FAFgYzH B+VDw3ZZTxpQnzciQJpSobiCMDuauGytFF+9DeK6UBbZB3JvMFxcxA7cDWJaze/5RD/B fpymv7mO5NEhF4/bNd3+yqDStkhWXLIo/so98eGAiAQKgdWy4QMoPXynxNIGs0dMZJZ9 C+Pw== MIME-Version: 1.0 X-Received: by 10.140.23.52 with SMTP id 49mr47830537qgo.17.1392825183925; Wed, 19 Feb 2014 07:53:03 -0800 (PST) Sender: carpeddiem@gmail.com Received: by 10.140.31.68 with HTTP; Wed, 19 Feb 2014 07:53:03 -0800 (PST) In-Reply-To: <20140219230824.0f2ba24b@X220.alogt.com> References: <20140218180646.GA67861@schlappy> <20140219144728.GA3036@schlappy> <20140219230824.0f2ba24b@X220.alogt.com> Date: Wed, 19 Feb 2014 10:53:03 -0500 X-Google-Sender-Auth: 1fP6CbASp3MqYFUsCHtCwlsb_4M Message-ID: Subject: Re: pthread programming eats up resources (My or FreeBSD's fault?) From: Ed Maste To: Erich Dollansky Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org, Andre Albsmeier , freebsd-threads@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Feb 2014 15:53:05 -0000 On 19 February 2014 10:08, Erich Dollansky wrote: > Hi, > > as I understand your program, it creates 1000 threads, waits a but and > then starts again creating 1000 threads until something kill it. > > From my point of view, your program depends very much on the default > settings of the environment. If the environment allows the immediate > execution of the new thread, you will never get many threads. > Otherwise, the number of threads hanging around could add up. It also > depends on the number of CPUs/cores your system has. > But your are right, it should not crash on a modern machine but it > still could use some amount of memory. Andre's second example program demonstrates the problem as well. It calls pthread_join() for each of the created threads, so should not be able to leave them around.