Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Feb 2014 11:39:02 +0800
From:      Erich Dollansky <erichsfreebsdlist@alogt.com>
To:        Andre Albsmeier <mail@ma17.ata.myota.org>
Cc:        freebsd-hackers@freebsd.org, freebsd-threads@freebsd.org
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>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

On Wed, 19 Feb 2014 17:24:41 +0100
Andre Albsmeier <mail@ma17.ata.myota.org> wrote:

I am now running this program:

> #include <stdio.h>
> #include <unistd.h>
> #include <pthread.h>
> 
> #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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140220113902.63e97b00>