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.