[Gc] Compilation test ?

Christophe Meessen meessen at cppm.in2p3.fr
Fri Jul 6 14:42:50 PDT 2007


Oops sorry. I didn't saw this in the documentation.

I still see problems with gc7.0 when trying to use static thread library
in release mode.
It is always the same error that I get back. It attempts to access
memory at address 10.
In debug I see no leaks at all.

I compiled the gc library with the following command, in case this matters
nmake /f NT_STATIC_THREADS_MAKEFILE NODEBUG=1

Here is the code that shows the problem.
When running in release mode it stops at first thread start.

----- main.cpp -----
#include <iostream>

#define GC_THREADS
#include <gc_cpp.h>

using namespace std;

unsigned int WINAPI startProxy(void* args)
{
    int* a = (int*)args;
    cout << "Starting thread with " << a[0] << a[1] << endl;
    try
    {
        for( int i = 0; i < a[0]; ++i )
        {
            Sleep( a[1] );
            cout << "Done sleeping..." << i << endl;
        }
    }
    catch( exception& e )
    {
        cout << "exception in thread: " << e.what() << endl;
    }
    cout << "Ending thread" << endl;
    return 0;
}

void start_thread( int n, int s )
{
    int* args = new int[2];
    args[0] = n;
    args[1] = s;
    unsigned int tid;
    uintptr_t hdl = GC_beginthreadex( 0, 0, &startProxy, (void*)args,
0,&tid);
    if( hdl == NULL )
        throw std::exception( "Thread creation failed" );
    CloseHandle( (HANDLE)hdl );
}


int main( int argc, char* argv )
{
    try
    {
        GC_INIT();
        cout << "GC_INIT done" << endl;
        while( true )
        {
            start_thread( 2, 50 );   
            Sleep( 1000 );
        }
        Sleep( 10000 );
    }
    catch( exception& e )
    {
        cout << "Exception: " << e.what() << endl;
    }
    return 0;
}





More information about the Gc mailing list