News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Using OpenMP in Thread

Started by seeing, October 23, 2010, 05:59:54 AM

Previous topic - Next topic

seeing

I have Created a DLL using openmp, the file is

extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}
//---------------------------------------------------------------------------

DLL_EXPORT void __stdcall Test(Byte *Source, int size)
{
  #pragma omp parallel for
    for(int i=0; i<size; i++)
    {
        if(Source[i] == 5)
            Source[i] = 22;
    }
}
//---------------------------------------------------------------------------


And I write a test program using by bcb, the code is

    int size = 10;
    Byte *src = new Byte[size];

    for(int i=0; i<size; i++)
        src[i] = i % 10;

    Test(src, size);

if I run this code in botton click event, it's ok.
But, if I run this code in Thread, it has crashed. Using GDB to debug, ths program received signal SIGSEGV, Segmentation fault.

why?

thanks a lot.

Jenna

Unrelated to C::B and therefore vioalting our forums/websites rules.

Please ask in an appropriate c++/openMP forum.

If you know what is wrong, but you don't know how (or where) to set it up in C::B, feel free to come back and ask again.

Topic locked !