Sponsored Content
Full Discussion: Memory LEAK with pthreads
Top Forums Programming Memory LEAK with pthreads Post 302313950 by JEscola on Thursday 7th of May 2009 05:32:01 AM
Old 05-07-2009
Network Memory LEAK with pthreads

I have this code...

#include <stdio.h>
#include <iostream>
#include <pthread.h>
static void* cliente(void *datos);

int main()
{
pthread_attr_t tattr;
int ret;
size_t size = PTHREAD_STACK_MIN + 0x0100;
ret = pthread_attr_init(&tattr);
ret = pthread_attr_setstacksize(&tattr, size);
ret= pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_JOINABLE);
ret=0;
pthread_t mythread[401];
while(ret<400)
{
int error=pthread_create((pthread_t *)&mythread[ret],&tattr,cliente,NULL);
if(error==0)pthread_detach((pthread_t)mythread);

ret++;
}

while(true)
{}
}
static void* cliente(void *datos)
{
char *buff=(char *)malloc(100000);
sleep(15);
free(buff);
buff=NULL;
pthread_exit(NULL);

}
When the code finishes I can observe that the virtual memory(report) in the creation of the threads is not liberated after doing a detach, even the memory(report) reserved also...

any body knows this problem???

TIA
 

9 More Discussions You Might Find Interesting

1. Programming

about virtual memory and memory leak

Hi, First of all I appreciate this group very much for its informative discussions and posts. Here is my question. I have one process whose virtual memory size increases linearly from 6MB to 12MB in 20 minutes. Does that mean my process has memory leaks? In what cases does the... (4 Replies)
Discussion started by: shriashishpatil
4 Replies

2. Programming

Problem with POSIX pthreads and virtual memory

Hi, i have this code... in order to test my problem... #include <stdio.h> #include <iostream> #include <pthread.h> static void* cliente(void *datos); int main() { pthread_attr_t tattr; int ret; size_t size = PTHREAD_STACK_MIN + 0x0100; ret =... (8 Replies)
Discussion started by: JEscola
8 Replies

3. UNIX for Advanced & Expert Users

Memory leak while using pthread_cancel()

I tried to execute a sample pthread program to cancel a newly created one using pthread_cancel(). but using valgrind on my code shows some memory leak. My Code: #include "iostream" #include "unistd.h" #include "pthread.h" #include "signal.h" using namespace std; void handler(int); void*... (4 Replies)
Discussion started by: kcr
4 Replies

4. UNIX for Advanced & Expert Users

Need to create a memory leak

Hi. This might be a strange request, but does anyone have any idea on a simple shell script that would use more and more memory as it ran? Like a purposeful leak. I want to test the behaviour of an already running program when the machine runs out of memory. Thanks! (4 Replies)
Discussion started by: rebelbuttmunch
4 Replies

5. IP Networking

memory leak?

Hi All, my client server application can work in two modes: 1) one direction - only client sends msgs to server 2) two directions - server gives 'answers' to client. when program run in the first mode it looks OK, but when server answers to client than client's application exit its... (2 Replies)
Discussion started by: lenna
2 Replies

6. Programming

memory leak problem

hi all Can any one plz explain me about memory leak problem Thankx (5 Replies)
Discussion started by: sonali
5 Replies

7. Programming

Memory Leak

Hi, I am trying a database server which keeps a B+ plus tree structure and works on it. I am trying to find the memory used/leak while executing this process. I check the memory leak by using ps uax command. When i execute a delete query i am sure that my code frees up the existing... (9 Replies)
Discussion started by: kumaran_5555
9 Replies

8. Red Hat

Memory leak

Hi all I am using RED HAT 5.4, and i am getting memory uses problem. when i use "sync;echo 3 > /proc/sys/vm/drop_cache" command the memory will release after 2,3 hour memory show 95%. pls suggest right way. thanks (37 Replies)
Discussion started by: reply.ravi
37 Replies

9. Programming

Help regarding memory leak in this C program

I have written this code in C which reads a very large collection of text files and does some processing. The problem with this code is that there are memory leaks which I am not able to figure out as to where the problem is. When I run this code, and see the memory usage using top command, then I... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies
PAPI_set_granularity(3) 					       PAPI						   PAPI_set_granularity(3)

NAME
PAPI_set_granularity - Set the default counting granularity for eventsets bound to the cpu component. SYNOPSIS
Detailed Description @par C Prototype: int PAPI_set_granularity( int granularity ); @param -- granularity one of the following constants as defined in the papi.h header file @arg PAPI_GRN_THR -- Count each individual thread @arg PAPI_GRN_PROC -- Count each individual process @arg PAPI_GRN_PROCG -- Count each individual process group @arg PAPI_GRN_SYS -- Count the current CPU @arg PAPI_GRN_SYS_CPU -- Count all CPUs individually @arg PAPI_GRN_MIN -- The finest available granularity @arg PAPI_GRN_MAX -- The coarsest available granularity Return values: PAPI_OK PAPI_EINVAL One or more of the arguments is invalid. PAPI_set_granularity sets the default counting granularity for all new event sets created by PAPI_create_eventset. This call implicitly sets the granularity for the cpu component (component 0) and is included to preserve backward compatibility. Example: int ret; // Initialize the library ret = PAPI_library_init(PAPI_VER_CURRENT); if (ret > 0 && ret != PAPI_VER_CURRENT) { fprintf(stderr,"PAPI library version mismatch!0); exit(1); } if (ret < 0) handle_error(ret); // Set the default granularity for the cpu component ret = PAPI_set_granularity(PAPI_GRN_PROC); if (ret != PAPI_OK) handle_error(ret); ret = PAPI_create_eventset(&EventSet); if (ret != PAPI_OK) handle_error(ret); * See Also: PAPI_set_cmp_granularity PAPI_set_domain PAPI_set_opt PAPI_get_opt Author Generated automatically by Doxygen for PAPI from the source code. Version 5.2.0.0 Tue Jun 17 2014 PAPI_set_granularity(3)
All times are GMT -4. The time now is 08:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy