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.
#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);
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.