[Gc] Multithreaded C program does not work as well

Achilleas Margaritis axilmar at otenet.gr
Sun Dec 16 02:29:21 PST 2007


The following simple C program dies a horrible death:

#include <gc.h>
#include <pthread.h>
#include <stdio.h>

void *thread_proc(void *p) {
     struct GC_stack_base sb;
     int i;

     GC_get_stack_base(&sb);
     GC_register_my_thread(&sb);

     for(i = 0; i < 100000; ++i) {
         void *p = GC_malloc(1000);
     }

     GC_unregister_my_thread();

     printf("finished\n");

     return 0;
}

int main() {
     int i;

     GC_INIT();

     for(i = 0; i < 10; ++i) {
         pthread_t handle;
         pthread_create(&handle, 0, thread_proc, 0);
     }

     getchar();
     return 0;
}



More information about the Gc mailing list