Multithreading in Visual C++ programmes 
Author Message
 Multithreading in Visual C++ programmes

Hi there,
I have some C++ code that calls a fortran routine which takes between
60seconds and four or five minutes to complete and return back.
The actual FORTRAN code is working fine (in the de{*filter*} I can watch
variables and check that they're being changed correctly).
However, once control returns back from the routine the programme crashes in
thrdcore.cpp at the line:

   if (IsIdleMessage(&m_msgCur))
   {
    bIdle = TRUE;
    lIdleCount = 0;
   }

15bytes in, actually, at the code line
5F438D3D   call        dword ptr [edx+6Ch]
(if that helps, which I doubt).

My guess is that the FORTRAN routine is taking so long that it is blocking
programme message processing.  Is this likely/possible?
Because I'm fairly new to all this, my next guess may well sound stupid, but
I think I should start the FORTRAN routine as a separate thread.
Reading up on this, it appears that routines started in separate threads can
only have one argument passed to them.  If so, then I don't know what to do
as the FORTRAN routine requires six parameters.

Any suggestions welcome,

Charlie



Sun, 29 Sep 2002 03:00:00 GMT  
 Multithreading in Visual C++ programmes
Charlie,

I don't know the answer to your crash, but I can answer you thread parameter
question. The single parameter passed into the thread procedure can be a
pointer to a structure containing the several parameters needed by your
Fortran function.

--
Dave Smith
MCSE, MCT, MVP

Quote:

>Hi there,
>I have some C++ code that calls a FORTRAN routine which takes between
>60seconds and four or five minutes to complete and return back.
>The actual FORTRAN code is working fine (in the de{*filter*} I can watch
>variables and check that they're being changed correctly).
>However, once control returns back from the routine the programme crashes
in
>thrdcore.cpp at the line:

>   if (IsIdleMessage(&m_msgCur))
>   {
>    bIdle = TRUE;
>    lIdleCount = 0;
>   }

>15bytes in, actually, at the code line
>5F438D3D   call        dword ptr [edx+6Ch]
>(if that helps, which I doubt).

>My guess is that the FORTRAN routine is taking so long that it is blocking
>programme message processing.  Is this likely/possible?
>Because I'm fairly new to all this, my next guess may well sound stupid,
but
>I think I should start the FORTRAN routine as a separate thread.
>Reading up on this, it appears that routines started in separate threads
can
>only have one argument passed to them.  If so, then I don't know what to do
>as the FORTRAN routine requires six parameters.

>Any suggestions welcome,

>Charlie



Sun, 29 Sep 2002 03:00:00 GMT  
 Multithreading in Visual C++ programmes
I have a C++ program that calls a C++ routine that takes about 15 minutes to
execute (if there is enough
virtual memory, that is). I've never had the problem you have, and I've
never heard about "a function taking
too long" from windows (of course, I've heard that often enough from my
customers...).
Is it possible that your code does some message processing (like
PumpMessage, PeekMessage, ...)?
This could disturb MFC.
Niki

Quote:
> Hi there,
> I have some C++ code that calls a FORTRAN routine which takes between
> 60seconds and four or five minutes to complete and return back.
> The actual FORTRAN code is working fine (in the de{*filter*} I can watch
> variables and check that they're being changed correctly).
> However, once control returns back from the routine the programme crashes
in
> thrdcore.cpp at the line:

>    if (IsIdleMessage(&m_msgCur))
>    {
>     bIdle = TRUE;
>     lIdleCount = 0;
>    }

> 15bytes in, actually, at the code line
> 5F438D3D   call        dword ptr [edx+6Ch]
> (if that helps, which I doubt).

> My guess is that the FORTRAN routine is taking so long that it is blocking
> programme message processing.  Is this likely/possible?
> Because I'm fairly new to all this, my next guess may well sound stupid,
but
> I think I should start the FORTRAN routine as a separate thread.
> Reading up on this, it appears that routines started in separate threads
can
> only have one argument passed to them.  If so, then I don't know what to
do
> as the FORTRAN routine requires six parameters.

> Any suggestions welcome,

> Charlie



Sun, 29 Sep 2002 03:00:00 GMT  
 Multithreading in Visual C++ programmes

Quote:

> Hi there,
> I have some C++ code that calls a FORTRAN routine which takes between
> 60seconds and four or five minutes to complete and return back.
> The actual FORTRAN code is working fine (in the de{*filter*} I can watch
> variables and check that they're being changed correctly).
> However, once control returns back from the routine the programme crashes in
> thrdcore.cpp at the line:

>    if (IsIdleMessage(&m_msgCur))
>    {
>     bIdle = TRUE;
>     lIdleCount = 0;
>    }

> 15bytes in, actually, at the code line
> 5F438D3D   call        dword ptr [edx+6Ch]
> (if that helps, which I doubt).

> My guess is that the FORTRAN routine is taking so long that it is blocking
> programme message processing.  Is this likely/possible?
> Because I'm fairly new to all this, my next guess may well sound stupid, but
> I think I should start the FORTRAN routine as a separate thread.
> Reading up on this, it appears that routines started in separate threads can
> only have one argument passed to them.  If so, then I don't know what to do
> as the FORTRAN routine requires six parameters.

> Any suggestions welcome,

> Charlie

When you call one language from another a likely suspect is a calling convention
mismatch.  Single-step through the assembly language and note the stack value
(ESP in the register window) before the call and after the FORTRAN function
returns.  If it doesn't match a crash will soon follow.  A penny says your edx
value came out of the wrong place in the stack after the return.

To use a thread put all the parameters in a struct and pass a pointer to the
struct to a C thread function.  Then you can take the struct apart and pass it
however you need to into the FORTRAN function.

--
Scott McPhillips [VC++ MVP]



Sun, 29 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need a good tutorial on multithreading in Visual C++ 6.0

2. Multithreading in Visual C++

3. I want a multithreading sample(Visual C++ mfc)!!!!

4. Visual C++ .NET coexisting with Visual C++ v6.0 SP5

5. Visual C++ to eMbedded Visual C++ problem

6. Visual C++ .NET reviews, comparisons to Visual C++ 6.0

7. Do Not Install Visual C++ 5.0 Over an Installation of Visual C++ 4.x

8. Visual C++ 6.0 vs. Visual C++ .NET

9. Visual C++ .NET coexisting with Visual C++ v6.0 SP5

10. Visual C++ 6.0 contra Visual C++ Technology Preview IE4

11. Visual C++ calling Visual C++ dll

12. How to compile Visual C++ 1.0 source code using Visual C++ 4.0

 

 
Powered by phpBB® Forum Software