[Gc] Re: Does thread support work for the windows 7.0 version?

Achilleas Margaritis axilmar at otenet.gr
Sat Dec 15 18:07:57 PST 2007

Something fishy is going on. When I run a program with one thread using 
the gc, everything is fine. When I run two threads on the gc, it 
crashes. Here is the test program, compiled with GC_NOT_DLL:

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

int rnd(int i) {
     return rand() % i;

void test() {
     for(int i = 0; i < 100000; ++i) {
         void *mem = GC_malloc(rnd(10) + 1000);

void *thread_proc(void *param) {
     GC_stack_base sb;
     return 0;

int main() {
     pthread_t handle;
     for(int i = 0; i < 1; ++i) pthread_create(&handle, 0, thread_proc, 0);


     return 0;

The program above is compiled with the release version of the gc (nmake 
nodebug=1 CFG="gc - win32 release").

If I run one thread only, then the program works if the number of 
allocations is 10000, even if the main thread is allocating gc data.

If the number of allocations goes up to 100000, it does not work: it 
seems the collector is stuck somewhere.

If the number of threads goes up to 5, the program crashes.

Compiling the program with GC_WIN32_THREADS and using GC_CreateThread to 
allocate threads, the program crashes if I put an std::list variable.

I think the collector is broken for multiple threads under win32...

O/H Hans Boehm έγραψε:
> I haven't had time to run the code.  As far as I know, it should work,
> though there may be an issue with the way the collector was built.
> Can you run gctest.exe with the same library version?  I didn't
> immediately notice your code doing anything that gctest does not do.
> Hans
> On Sat, 15 Dec 2007, Achilleas Margaritis wrote:
>> Dear mr Hans Boehm,
>> I have posted my problem with the gc a few days ago but I still do not
>> have a reply from you about it.
>> Should I wait for your reply? is it something I am doing wrong in my
>> code? should I use another version of the gc? does thread support work
>> for the 7.0 version of the collector?
>> I would be grateful if you can respond to this in the next few days,
>> because I have a customer waiting for a reply from me on a project that
>> its feasibility depends on the gc (your gc, there are no other
>> collectors for c++).
>> Best regards
>> Achilleas Margaritis
>> _______________________________________________
>> Gc mailing list
>> Gc at linux.hpl.hp.com
>> https://www.hpl.hp.com/hosted/linux/mail-archives/gc/

More information about the Gc mailing list