-lmcheck is not thread safe, or it is not safe at all.

Gao, Clark (NSN - CN/Cheng Du) clark.gao@nsn.com
Tue Oct 14 04:33:00 GMT 2008


 
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);
     }
}



More information about the Glibc-bugs mailing list