472,780 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

(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.

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <omp.h>
  3.  
  4. public __gc class TestClass
  5. {
  6. public:
  7.     void ThreadProc()
  8.     {
  9.         int sum = 0;
  10.  
  11. #pragma omp parallel for reduction(+:sum)
  12.         for ( int i = 0; i < 10000; i++ )
  13.         {
  14.             sum += i;
  15.         }
  16.  
  17.         System::Console::WriteLine( sum.ToString() );
  18.     }
  19. };
  20.  
  21. int main()
  22. {
  23.     for (;;)
  24.     {
  25.         TestClass __gc * o = __gc new TestClass();
  26.         System::Threading::Thread __gc * t = __gc new System::Threading::Thread( 
  27.                     __gc new System::Threading::ThreadStart( o, &TestClass::ThreadProc ) );
  28.  
  29.         t->Start();
  30.  
  31.         System::Threading::Thread::get_CurrentThread()->Sleep( 100 );
  32.     }
  33. }
  34.  
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.
Oct 1 '07 #1
2 2476
I think i have got ur problem. there are unmanaged threads when using openmp.is it so?

openmp architecture is like when u specify the openmp pragma, it creates a new thread for ur loop and once finished joins the main thread.this might be ur problem. I am not versatile in openmp. But this is a new concept only less ppl use it.so keep in touch to discuss about openmp
Oct 5 '07 #2
We recently discovered that the thread leak has nothing to do with .NET. The same leak occurs even if we run OpenMP code inside a Win32 thread. So, here is the new example. Suggestions\ideas, please?

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <omp.h>
  4.  
  5. int calculateArithmeticalProgressionSumOMP( int a1, int d, int n )
  6. {
  7.     int sum = 0;
  8.     omp_set_num_threads(3);
  9. #pragma omp parallel 
  10.     {
  11. #pragma omp for reduction (+: sum)
  12.         for( int i = 0; i < n; i++)
  13.         {
  14.             int a = a1 + i * d;
  15.             sum += a;                                                                                                                                                                                      
  16.         }
  17.     }
  18.     return sum;
  19. }
  20.  
  21. DWORD threadFunc(LPVOID pParams)
  22. {
  23.     int sum = calculateArithmeticalProgressionSumOMP(0, 1, 10000);
  24.     printf("%d\n", sum);
  25.     return 0;
  26. }
  27.  
  28. int main()
  29. {
  30.     //create some threads
  31.     for(int i = 0; i < 100; i++)
  32.     {
  33.         HANDLE handle;
  34.         handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE )threadFunc, NULL, 0, NULL);
  35.         WaitForSingleObject(handle, INFINITE);
  36.         Sleep(100); //imitating some other work
  37.     }
  38.  
  39.     return 0;
  40. }
  41.  
  42.  
Nov 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David | last post by:
I've written a small windows service, and I'm having a problem that I'm spending a lot more time on than I'd like. If anyone has experienced this problem and has any hints or solutions; they would...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
1
by: Brian C. Barnes | last post by:
Will OpenMP (or some other parallelizing technology) be considered for C#, like C++ already has? Brian C. Barnes
5
by: Vladimir_petter | last post by:
Hello guys, Looks like this technology is comming along with VS2005. Anybody has an expirience of using it along with C++? What are the patterns? Thanks, Vladimir.
1
by: Carl J. Van Arsdall | last post by:
Hey everyone, I know I've posted several questions regarding python and python's parallel capabilities so bear with me as I've never attempted to incite discussion. However, today I'm...
2
by: san | last post by:
Hi, I am not sure whether this is the right group to post this. Still here I go: I am new to OpenMP. I wrote a very simple code in C++. The code is as below #include <iostream.h> #include...
0
by: BallCOMET | last post by:
I have an application that I built with Visual Studio 2005 and for which I enabled OpenMP. If I open the compiled binary in Visual Studio, this is the manifest that is embedded in the executable...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
6
by: Renato Perini | last post by:
Hi all!!! I'm trying to find a *good* book about OpenMP and C, but I can't find anything specific. Can you advice me some good (and updated) books about OpenMP using the C interface? I'd like a...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.