in reply to Re^7: memory leaks with threads
in thread memory leaks with threads
I'm running Linux, 2.6.18, 32bit on a turion x2 tl-60.
I just ran a similar program written in c.
It doesn't grow (stays exactly at a res memory of 944B), also after 15 million threads created and destroyed.
So I can at least say it's not related to my pthreads library.
I'll however wait a bit before submitting a bug report, maybe someone else knows a solution.
I just ran a similar program written in c.
It doesn't grow (stays exactly at a res memory of 944B), also after 15 million threads created and destroyed.
So I can at least say it's not related to my pthreads library.
I'll however wait a bit before submitting a bug report, maybe someone else knows a solution.
#include <iostream> #include <cstdlib> using namespace std; #include <pthread.h> #include <unistd.h> #include <sys/select.h> #include <sys/time.h> using namespace std; static int threadscount = 0; pthread_mutex_t threadscount_mutex = PTHREAD_MUTEX_INITIALIZER; void* thread( void* data ){ pthread_mutex_lock( &threadscount_mutex ); threadscount--; //cout << threadscount << endl; pthread_mutex_unlock( &threadscount_mutex ); pthread_exit(0); } int main(int argc, char *argv[]){ int count = 0; int a; struct timeval timeout; while (1){ for ( int a = 1; a <= 10; a++ ){ pthread_mutex_lock( &threadscount_mutex ); threadscount++; pthread_mutex_unlock( &threadscount_mutex ); pthread_t p_thread; /* thread's structu +re */ pthread_create(&p_thread, 0, thread, (void*)&a +); pthread_detach( p_thread ); count ++; } cout << "count: " << count << endl; int c; do { timeout.tv_usec = 100; timeout.tv_sec = 0; select( 0, 0, 0, 0, &timeout ); pthread_mutex_lock( &threadscount_mutex ); c = threadscount; pthread_mutex_unlock( &threadscount_mutex ); } while ( c > 0); } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^9: memory leaks with threads
by BrowserUk (Patriarch) on Jul 09, 2007 at 23:33 UTC | |
by misc (Friar) on Jul 10, 2007 at 13:34 UTC | |
by BrowserUk (Patriarch) on Jul 10, 2007 at 13:57 UTC |
In Section
Seekers of Perl Wisdom