Expand|Select|Wrap|Line Numbers
- #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 );
- }
- }
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.