(OpenMP, C++ME, System.Threading.Thread) -> Resource Leak.
Here is the source code of my C++/ME app. When I run it I can use "Windows Task Manager" to see that thread HANDLEs are leaking.
#include "stdafx.h"
#include <omp.h>
public __gc class TestClass
{
public:
void ThreadProc()
{
int sum = 0;
#pragma omp parallel for reduction(+:sum)
for ( int i = 0; i < 10000; i++ )
{
sum += i;
}
System::Console::WriteLine( sum.ToString() );
}
};
int main()
{
for (;;)
{
TestClass __gc * o = __gc new TestClass();
System::Threading::Thread __gc * t = __gc new System::Threading::Thread(
__gc new System::Threading::ThreadStart( o, &TestClass::ThreadProc ) );
t->Start();
System::Threading::Thread::get_CurrentThread()->Sleep( 100 );
}
}
If I put something that is not using Open MP into the ThreadProc no HANDLEs will be leaked.
I realize that what happens is: Omp creates unmanaged threads inside a managed thread (i.e. System::Threading::Thread). I just have very little idea about what could be wrong with it. If somebody will try to reproduce this, I am currently using VS2005.
Thanks for all your comments and suggestions.
[1282 byte] By [
Pimp_Daddy] at [2007-11-20 11:06:47]

# 1 Re: (OpenMP, C++ME, System.Threading.Thread) -> Resource Leak.
Make sure that there isn't any other call needed in the thread proc to tell omp to free up the handles.
As a test, could you put the omp operations into a function and run it from the main thread several times to see if there are handle leaks?
Arjay at 2007-11-9 13:59:40 >

# 2 Re: (OpenMP, C++ME, System.Threading.Thread) -> Resource Leak.
Well, there are no handle-freeing calls that I know of. As I understood Open MP is supposed to let me create multithreaded applications without having to think about threads, handles and that kind of stuff.
I tried running the code from the main thread. No leaks.
I have just compiled the omp code in a separate unmanaged lib using Intel's compiler. It seems not to have this problem...
I'm still curious about what is going on with MSC++ here.