[PLUG] Malloc and Glibc
Mathew, Tisson K
tisson.k.mathew at intel.com
Wed Nov 27 16:47:40 UTC 2002
Thanks Karl,
Sorry for missing the header files, it was a cut-paste error. I have seen it
running without any problems for a longer time with 100msec sleep,
eventually it will seg fault but without the sleep it seg faults sooner both
times the seg fault is at either chunk_alloc or chunk_free (I have made the
sleep to one iteration of the for loop in the code below). Apparently it
works fine if I add mutex around malloc and free.
I'm running a XScale Linux ( Kernel Version 2.4.7 ) distribution from
LynuxWorks (http://www.lynuxworks.com/products/bluecat/bluecat.php3) & glibc
2.2.2
-------------------------------------------------------------
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#define MYSIZE (1*1024)
#define SLEEP_TIME (100*1000) // usec
void *AllocThread(void *pvArg);
int main(int argc, char **argv)
{
pthread_t hThread;
int ii;
int iLimit=12;
for(ii=0;ii<iLimit;ii++)
pthread_create(&hThread,NULL,AllocThread,NULL);
AllocThread(NULL);
return 0;
}
void *AllocThread(void *pvArg)
{
struct timeval tv{0,SLEEP_TIME}; /*sleep only at the first iteration */
char *pBuff=NULL;
for(;;)
{
if((pBuff=(char *)malloc(MYSIZE))==NULL)
printf("Could not alloc in parent!\n");
else
memset(pBuff,0x05,MYSIZE);
select(0,NULL,NULL,NULL,&tv);
if(pBuff)
free(pBuff);
}
return NULL;
}
/* compile: gcc -o malloc_test malloc_test.c -l pthread */
------------------------------------------------------------
thanks
-tisson
-----Original Message-----
From: Karl M. Hegbloom [mailto:karlheg at pdxlinux.org]
Sent: Tuesday, November 26, 2002 9:12 PM
To: 'plug at lists.pdxlinux.org'
Cc: plug-devel at lists.pdxlinux.org
Subject: RE: [PLUG] Malloc and Glibc
On Tue, 2002-11-26 at 14:43, Mathew, Tisson K wrote:
> Here is the code; I'm running glibc 2.2.2 on XScale iq80320.
And that compiles, but does not run, it causes segmentation violations?
When does it crash?
It would not build as shown; I had to add some #include directives.
Attached is what I was able to compile and run. It seems to work fine.
You'll see comments showing it running; a "ps wwwauxf" excerpt.
Here's the ldd output against the finished binary, running on ia32 (Dual
P-III).
karlheg at bittersweet:src/TestingGrounds
% ldd ./alloc_thread
libpthread.so.0 => /lib/libpthread.so.0 (0x4002d000)
libc.so.6 => /lib/libc.so.6 (0x4007e000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
karlheg at bittersweet:src/TestingGrounds
% ls -l /lib/libpthread.so.0 /lib/libc.so.6 /lib/ld-linux.so.2
lrwxr-xr-x 1 root root 18 Nov 21 01:19 /lib/libpthread.so.0
-> libpthread-0.10.so
lrwxr-xr-x 1 root root 13 Nov 21 01:19 /lib/libc.so.6 ->
libc-2.3.1.so*
lrwxr-xr-x 1 root root 11 Nov 21 01:19 /lib/ld-linux.so.2
-> ld-2.3.1.so*
More information about the PLUG
mailing list