This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
RE: malloc and threads
- From: "Mathew, Tisson K" <tisson dot k dot mathew at intel dot com>
- To: "'Wolfram Gloger'" <Wolfram dot Gloger at dent dot med dot uni-muenchen dot de>
- Cc: libc-alpha at sources dot redhat dot com, "Mathew, Tisson K" <tisson dot k dot mathew at intel dot com>
- Date: Wed, 27 Nov 2002 08:43:03 -0800
- Subject: RE: malloc and threads
Thanks Wolfram,
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.
XScale is an ARM based processor ( http://www.intel.com/design/intelxscale/
)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 and Linux Kernel Dev for ARM is maintained by Russell King (
http://www.arm.linux.org.uk ).
-------------------------------------------------------------
#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: Wolfram Gloger [mailto:Wolfram.Gloger@dent.med.uni-muenchen.de]
Sent: Wednesday, November 27, 2002 5:37 AM
To: tisson.k.mathew@intel.com
Cc: libc-alpha@sources.redhat.com
Subject: Re: malloc and threads
Hello,
> Here is the code; I'm running glibc 2.2.2 on XScale iq80320.
>
> --------------------------
> #define MYSIZE (1*1024)
> #define SLEEP_TIME (100*1000) // usec
>
> void *AllocThread(void *pvArg);
After adding
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
and compiling with -pthread, I am able to run this test successfully
for hours, on ix86 with glibc-2.2.5. Same on an old system with
glibc-2.1.3 on it.
Sorry, I have no idea what an "iq80320" is.
Regards,
Wolfram.