Solved

Why does my Thread hang?

Posted on 2009-05-08
3
314 Views
Last Modified: 2013-11-25
Im developing a windows application (not Internet based) using Visual Studio 2008 and Visual C#. Its an MDI application.

The thread enters this "getTriggerWaveform_DLL" function (shown below) but very occasionally never  returns from it. It just vanishes into a black hole. I cant set debugging for this function either. Ive tried and I asked on this forum but the solutions proposed dont work. The function is compiled into a DLL. The thing is Id expect it to at the very least throw an exception back to the calling statement.

Can anyone suggest a modification to this routine such that I should always get an exception thrown back if something goes wrong?

extern "C" __declspec(dllexport) double* getTriggerWaveform_DLL(long channelNo, long noOfPoints, double* timeIncrement, double* startTime) throw(exception) {
      double* results = new double[noOfPoints];

      try{
            theDSO -> getTriggerWaveform(channelNo, noOfPoints, results, timeIncrement, startTime);
      } catch(DSOCPPException e){
            setLastException(e.what());
            throw e;
      }
      return results;
}
0
Comment
Question by:rangers99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 150 total points
ID: 24334432
How do you know that getTriggerWaveform ever returns? How do you know it's a C++ exception being thrown? It might be a structured exception being thrown, not a C++ exception. For this you need to look at Structured Exception Handling (SEH).

http://msdn.microsoft.com/en-us/library/ms680657(VS.85).aspx
http://msdn.microsoft.com/en-us/library/8c522k35.aspx

Also, exceptions should NEVER be allowed to cross an API boundary. The calling langauge may not be the same as the libraries language. So, if getTriggerWaveform was a managed code DLL, for example, and it throws a managed exception across the API boundary you have absolutely no chance of catching it using unmanaged C++.
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 150 total points
ID: 24334452
Additional...

catch(DSOCPPException e)

NEVER catch by value... if it's a polymorphic exception class you'll slice it. Also, you'll copy the exception object (wasteful). Always catch by reference and catch using the highest type int he class hierarchy that you can so as to be able to discern the exception type.

catch(std::runtime_error const & e)
{
}
catch(std::exception const & e)
{
}

Do you expect DSOCPPException from this function?
0
 

Author Comment

by:rangers99
ID: 24336380
evilrx
Thanks for those  answers. Im inexperienced at this but Ill read the those links. cheers.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question