vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Recently I'm writing a little program and trying to make it portable under Linux, Solaris, HP-UX, AIX... The program uses pthread functions. As the manual metioned, threads must either be pthread_join()ed or pthread_detach()ed, otherwise resources occpied by them are not reclaimed. I found that on AIX, even if I called pthread_join() on every threads, the are still there, when using the command: /usr/sysv/bin/ps -eLf. I write some code to test: #include <pthread.h> #include <stdio.h> #define THREAD_COUNT 550 void *test_proc(void *arg) { printf("me %d\n", pthread_self()); return NULL; } int main(int argc, char *argv[]) { pthread_t tid[THREAD_COUNT]; pthread_attr_t attr; int i; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED); fgetc(stdin); for (i = 0; i < THREAD_COUNT; i++) { pthread_create(&tid[i], NULL, test_proc, NULL); } pthread_attr_destroy(&attr); fgetc(stdin); void *dummy; for (i = 0; i < THREAD_COUNT; i++) { printf("%d %d\n", tid[i], pthread_join(tid[i], &dummy)); } fgetc(stdin); return 0; } cc_r o- pthread_test pthread_test.c At every point of the three fgetc() calls, using /usr/bin/ps or /usr/ sysv/bin/ps to watch VSZ, RSS and LWP,NLWP values, I get the conclusion that after pthread_join(), some (but not all) threads are still there, and resources(VSZ, RSS) allocted by pthread_create() are not released. |
| |||
| > pthread_attr_t attr; > pthread_attr_init(&attr); > pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED); > pthread_create(&tid[i], NULL, test_proc, NULL); You should use attr somewhere, namely in pthread_create. JD |
| |||
| On 4月11日, 下午3時28分, "Jedrzej Dudkiewicz" <jedrzej.dudkiew...@poczta.interia.pl> wrote: > > pthread_attr_t attr; > > pthread_attr_init(&attr); > > pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED); > > pthread_create(&tid[i], NULL, test_proc, NULL); > > You should use attr somewhere, namely in pthread_create. > > JD thanks, I've tried that, it still have no effect. The threads are still there, whether using attr no not using attr. :-( |
| |||
| larkvm@gmail.com writes: > I found that on AIX, even if I called > pthread_join() on every threads, the are still there No you didn't. > At every point of the three fgetc() calls, using /usr/bin/ps or /usr/ > sysv/bin/ps to watch VSZ, RSS and LWP,NLWP values, I get the > conclusion that after pthread_join(), some (but not all) threads are > still there, and resources(VSZ, RSS) allocted by pthread_create() are > not released. Your observed results are correct, but your conclusion is not. Resources allocated by pthread_create are not released (they are cached since you are likely to create more threads). But that doesn't mean the threads are "there". They are gone, turned into "available memory" in exactly the same way as memory is "gone" after you do: p = calloc(10000, 1); free(p); [BTW, unlike Linux and Solaris which use mmap() to "allocate" thread stack, AIX uses malloc() for the same.] Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. |
| ||||
| On 4月12日, 下午1時45分, Paul Pluzhnikov <ppluzhnikov-...@charter.net> wrote: > lar...@gmail.com writes: > > I found that on AIX, even if I called > > pthread_join() on every threads, the are still there > > No you didn't. > > > At every point of the three fgetc() calls, using /usr/bin/ps or /usr/ > > sysv/bin/ps to watch VSZ, RSS and LWP,NLWP values, I get the > > conclusion that after pthread_join(), some (but not all) threads are > > still there, and resources(VSZ, RSS) allocted by pthread_create() are > > not released. > > Your observed results are correct, but your conclusion is not. > > Resources allocated by pthread_create are not released (they are > cached since you are likely to create more threads). > > But that doesn't mean the threads are "there". They are gone, > turned into "available memory" in exactly the same way as memory is > "gone" after you do: > > p = calloc(10000, 1); > free(p); > > [BTW, unlike Linux and Solaris which use mmap() to "allocate" > thread stack, AIX uses malloc() for the same.] > > Cheers, > -- > In order to understand recursion you must first understand recursion. > Remove /-nsp/ for email. thank you very much! Now I recognized that on AIX it's not a 'leak', thanks again :-) |
| Thread Tools | |
| Display Modes | |
|
|