[Gc] multithreaded application on sparc

Petr Krajca krajcap at inf.upol.cz
Sat Sep 29 15:24:41 PDT 2007


hello,

i'm porting application on the ultrasparc machine (T1, sun4v, 8GiB RAM,  
debian linux 4.0 -- etch) and i found strange behavior while using  
multiple threads and GC. (GC 6.8 with --enable-threads=posix  
--enable-thread-local-alloc --enable-parallel-mark)

in the attached example some threads are aborted (without any  
warning)...probably due to insufficient memory... it seems that GC is not  
triggering collector to clean up unused memory.

does anybody know what's wrong?

best regards,
petr krajca


#define GC_THREADS
#include <gc/gc.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>

void * routine(void * arg)
{
         int i;
         printf("start:\t%i\n", arg); fflush(stdout);
         for (i = 0; i < 100000; i++) {
                 int * z = GC_MALLOC(sizeof(int));
                 *z = 2 * i;
         }
         printf("done:\t%i\n", arg); fflush(stdout);
}

void * appl(void * x)
{
         int i;
         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
         for (i = 0; i < 100; i++) {
                 pthread_t t;
                 pthread_attr_t attr;
                 pthread_attr_init(&attr);
                 pthread_attr_setdetachstate(&attr,  
PTHREAD_CREATE_DETACHED);
                 int q = pthread_create(&t, NULL, routine, i);
                 pthread_detach(t);
         }
}

int main()
{
         GC_INIT();
         GC_set_max_heap_size(1000000);

         pthread_t x;
         pthread_create(&x, NULL, appl, NULL);

         sleep(10);
         pthread_join(x, NULL);
         printf("welldone\n"); fflush(stdout);
         return 0;
}



More information about the Gc mailing list