This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
-lmcheck is not thread safe, or it is not safe at all.
- From: "Gao, Clark (NSN - CN/Cheng Du)" <clark dot gao at nsn dot com>
- To: "glibc-bugs at sourceware dot org" <'glibc-bugs at sourceware dot org'>
- Date: Tue, 14 Oct 2008 12:29:27 +0800
- Subject: -lmcheck is not thread safe, or it is not safe at all.
this is the test code. It will crash when I compiled it with -lmcheck,
but ok when I use MALLOC_CHECK_ .
I'm so frustrated. I trust the -lmcheck so much, but it waste me so many
time before I get aware the fault is coming from -lmcheck.
damn it.
========================================================================
=============
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
void* thread_func(void* arg)
{
while(1)
{
char* tmp = strdup("1234567890abcdefghijklmnopqrstuvwxyz");
//char* tmp = (char*)malloc(100);
if(tmp)
free(tmp);
usleep(1);
}
return NULL;
}
main()
{
pthread_t pid;
int i = 0;
for(i = 0;i < 200; i++){
pthread_create(&pid,0,thread_func,0);
}
printf("\nwaiting.\n");
while(1){
sleep(1000);
}
}