[Gc] Solaris and pthread problem

Boehm, Hans hans.boehm at hp.com
Thu Sep 2 14:02:00 PDT 2004


You should be able to define either GC_THREADS or GC_SOLARIS_PTHREADS, not GC_PTHREAD.

As to the second problem the documentation is a bit buggy (now fixed).  Don't call
GC_thr_init() directly.  Automatic initialization should work here, or you can call
GC_INIT().  (The documentation said to call GC_thr_init on Solaris X86 with malloc
redirected.  This was always a hack, and it broke at some point.  I'm planning
on a real solution for 7.0.  Before then, I'm inclined to declare malloc redirection
with threads broken on Solaris X86.  It already is on many other platforms, since
threads initialization allocates memory, which acquires locks, which requires threads
to be initialized.  The solution is to only lock if a second thread has started,
and probably to postpone some GC initialization.  I think none of this is relevant to your problem,
since you don't use malloc redirection.)

I'm sorry you didn't get a response the first time.

Hans


-----Original Message-----
From: gc-bounces at napali.hpl.hp.com [mailto:gc-bounces at napali.hpl.hp.com]On Behalf Of Simon Johansson
Sent: Thursday, September 02, 2004 4:49 AM
To: gc at napali.hpl.hp.com
Subject: [Gc] Solaris and pthread problem


Hi.
 
I have asked before almost the same question but now I try one more time.
 
I hope that some can tell me what I am doing wrong.
 
I have this small thread program that look like this:
 
#include <ctype.h>
#include <stdio.h>
#include <pthread.h>
 
#include <gc.h>
#define malloc(x) GC_malloc(x)
#define calloc(n,x) GC_malloc((n)*(x))
#define realloc(p,x) GC_realloc((p),(x))
#define free(x) (x)=NULL
 
pthread_attr_t uniface_attr_t;
pthread_t uniface_t;
 
 
void* do_uniface (void* loop)
{
 
 char *a= malloc(10000);
 
 free(a);
 
}
 
int main(void)
{
 
        int loop = 0;
        int result;
        int *th;
 
        GC_thr_init();
 
        th =(int*) malloc(4);
 
        pthread_attr_init(&uniface_attr_t); /* initialize attr with default attributes */
 
        while(1)
        {
 
                *th = loop;
 
                result = pthread_create (&uniface_t, &uniface_attr_t, do_uniface , th);
 
                if(result != 0)
                {
                        printf("Could not create thread");
                        exit(1);
                }
 
                loop++;
                fprintf (stderr,"\n%d: ",loop);
                sleep(1);
        }
 
}
 
 
I compile it like this:
 
gcc -g -I/home/ping/usr/new/gc6.3/sun/include -L/home/ping/usr/new/gc6.3/sun/lib/ -lgc -DGC_PTHREAD -DTHREAD_LOCAL_ALLOC test5.c
 
After running the program I always get this error.
 
#0  0xff36563c in GC_my_stack_limits () at solaris_threads.c:667
667         register size_t stack_size = me -> stack_size;
(gdb) where
#0  0xff36563c in GC_my_stack_limits () at solaris_threads.c:667
#1  0xff365258 in GC_old_stacks_are_fresh () at solaris_threads.c:556
#2  0xff360654 in GC_read_dirty () at os_dep.c:3225
#3  0xff358028 in GC_initiate_gc () at mark.c:237
#4  0xff34bd90 in GC_stopped_mark (stop_func=0xff34ac98 <GC_never_stop_func>) at alloc.c:505
#5  0xff34b7c8 in GC_try_to_collect_inner (stop_func=0xff34ac98 <GC_never_stop_func>) at alloc.c:367
#6  0xff34d234 in GC_collect_or_expand (needed_blocks=3, ignore_off_page=0) at alloc.c:998
#7  0xff355578 in GC_alloc_large (lw=2501, k=1, flags=0) at malloc.c:60
#8  0xff355c34 in GC_generic_malloc (lb=10000, k=1) at malloc.c:204
#9  0xff3560c4 in GC_malloc (lb=10000) at malloc.c:311
#10 0x109c0 in do_uniface (loop=0x47ff8) at /home/ping/testenv/U83:18
(gdb) print me
$1 = 0x0
(gdb) print *me
Cannot access memory at address 0x0
(gdb)
 
So ME is 0. 
 
The next step I took was to replace the -DGC_PTHREAD with -DGC_SOLARIS_PTHREADS.
 
When running the program I will get this error.
 
GC Warning: Insufficient space for /proc read
unexpected mark stack overflow
 
#0  0xff1d9764 in __sigprocmask () from /usr/lib/libthread.so.1
(gdb) where
#0  0xff1d9764 in __sigprocmask () from /usr/lib/libthread.so.1
#1  0xff1ce978 in _resetsig () from /usr/lib/libthread.so.1
#2  0xff1ce118 in _sigon () from /usr/lib/libthread.so.1
#3  0xff1d1158 in _thrp_kill () from /usr/lib/libthread.so.1
#4  0xff24b9dc in raise () from /usr/lib/libc.so.1
#5  0xff2358fc in abort () from /usr/lib/libc.so.1
#6  0xff35e5f8 in GC_abort (msg=0xff369dd0 "unexpected mark stack overflow") at misc.c:1071
#7  0xff359f38 in GC_push_all (bottom=0xbbd84000 "", top=0xbbd85000 "") at mark.c:1205
#8  0xff35ab08 in GC_push_all_stack (bottom=0xbbd84000 "", top=0xbbd85000 "") at mark.c:1519
#9  0xff35a084 in GC_push_selected (bottom=0xbbd84000 "", top=0xbbea4000 <Address 0xbbea4000 out of bounds>,
    dirty_fn=0xff360af8 <GC_page_was_ever_dirty>, push_fn=0xff35aac4 <GC_push_all_stack>) at mark.c:1246
#10 0xff365cd4 in GC_push_all_stacks () at solaris_threads.c:717
#11 0xff36028c in GC_default_push_other_roots () at os_dep.c:2045
#12 0xff35cd80 in GC_push_roots (all=1, cold_gc_frame=0xffbef364 "") at mark_rts.c:643
#13 0xff358694 in GC_mark_some (cold_gc_frame=0xffbef364 "") at mark.c:326
#14 0xff34bfe8 in GC_stopped_mark (stop_func=0xff34ae0c <GC_never_stop_func>) at alloc.c:520
#15 0xff34b93c in GC_try_to_collect_inner (stop_func=0xff34ae0c <GC_never_stop_func>) at alloc.c:367
#16 0xff34d368 in GC_collect_or_expand (needed_blocks=1, ignore_off_page=0) at alloc.c:998
#17 0xff34d75c in GC_allocobj (sz=20, kind=1) at alloc.c:1073
#18 0xff355a3c in GC_generic_malloc_inner (lb=75, k=1) at malloc.c:136
#19 0xff34f8b0 in GC_debug_generic_malloc_inner (lb=48, k=1) at dbg_mlc.c:573
#20 0xff3656dc in GC_new_thread (id=872) at solaris_threads.c:586
#21 0xff363a3c in GC_pthread_create (new_thread=0x20d4c, attr_in=0x20d40, thread_execp=0x10950 <do_uniface>,
    arg=0xff160ff8) at solaris_pthreads.c:155
#22 0x109f4 in main () at /home/ping/testenv/U83:40
(gdb)
 
So now I don't know what to test or try.
 
I am using GC6.3 and Solaris 8 on sparc system. 
 
When compiling GC I am using the following parameters -enable-threads=posix --enable-thread-local-alloc --enable-parallel-mark.
 
Hopefully there is some one that can explain way this is not working and what I shall do to make it work.
 
/Simon
 
 


More information about the Gc mailing list