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
- Date: Tue, 26 Nov 2002 13:50:00 -0800
- Subject: RE: malloc and threads
Thanks Wolfram,
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);
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;
char *pBuff=NULL;
for(;;)
{
if((pBuff=(char *)malloc(MYSIZE))==NULL)
printf("Could not alloc in parent!\n");
else
memset(pBuff,0x05,MYSIZE);
tv.tv_sec=0;
tv.tv_usec=SLEEP_TIME;
select(0,NULL,NULL,NULL,&tv);
if(pBuff)
free(pBuff);
}
return NULL;
}
------------------------------------------------------------
thanks
_tisson
-----Original Message-----
From: Wolfram Gloger [mailto:Wolfram.Gloger@dent.med.uni-muenchen.de]
Sent: Tuesday, November 26, 2002 9:12 AM
To: tisson.k.mathew@intel.com
Cc: libc-alpha@sources.redhat.com
Subject: Re: malloc and threads
Hi,
> A program that simply launches 10 threads that just malloc, wait 100
> milliseconds, and free the data and then loop.
Please post the code!
> This simple program segmentation faults. I'm using glibc version 2.2.2. I
> was wondering if malloc **still** has reentrancy problems or not ?
malloc never was reentrant and probably never will be.
If you mean "thread-safe", I'm not aware of any thread-related
problems in malloc, in particular not anything that would cause the
program described above to fail. That also holds for glicbc-2.2.2,
even though that's _really_ old now.
Regards,
Wolfram.