PRB: Multithreaded Program CrashesLast reviewed: December 9, 1995Article ID: Q118547 |
The information in this article applies to:
SYMPTOMSA program that uses the multithread run-time library fails to run to completion or generates a Dr. Watson access-violation error message.
CAUSEThis behavior can occur if the compile options are not consistent with the libraries included in linking.
RESOLUTIONIf the program is linked using the MSFRT.LIB and MSVCRT.LIB files, your object modules must be compiled using the -MD option. NOTE: This behavior was changed in Microsoft FORTRAN PowerStation version 4.0.
MORE INFORMATIONTo demonstrate the problem and workaround, compile the sample code below (TESTC), using the four different tests listed. The first two tests demonstrate the problem, while the last two tests show two sets of options that do not cause problems:
Test 1The TESTC created using these options will produce a Dr. Watson error message:
CL -c TESTC.CPP FL32 -LD TESTF.FOR FL32 -MD TESTC.OBJ TESTF.LIB Test 2The TESTC created using these options will not produce an error message, but will fail to run completely and will not produce any output:
CL -c -MD TESTC.CPP FL32 -LD TESTF.FOR FL32 -ML TESTC.OBJ TESTF.LIB -or- FL32 -MT TESTC.OBJ TESTF.LIB Test 3The TESTC created using these options will create a TESTC program that is linked to MSFRT.LIB and MSVCCRT.LIB. The actual run-time code is in the DLLs MSFRT10 and MSVCRT10. This TESTC will correctly display the message, "Factorial of 7 is: 5040":
CL -c -MD TESTC.CPP FL32 -LD TESTF.FOR FL32 -MD TESTC.OBJ TESTF.LIB Test 4The TESTC created using these options has the run-time code statically linked into the executable file. It will also correctly display the message, "Factorial of 7 is: 5040":
CL -c TESTC.CPP FL32 -LD TESTF.FOR FL32 -ML TESTC.OBJ TESTF.LIB -or- FL32 -MT TESTC.OBJ TESTF.LIB C Sample Code
/* Compile options needed: see text above */ #include <iostream.h> extern "C" {void __stdcall FACT (int n, int *amt);} int main() { int amt; FACT(7, &amt); cout << "Factorial of 7 is: " << amt; return 0; } FORTRAN Sample CodeC Compile options needed: see text above
SUBROUTINE Fact[DLLEXPORT](n, amt) INTEGER*4 n [VALUE] INTEGER*4 amt [REFERENCE] INTEGER*4 i amt = 1 DO i = 1, n amt = amt * i END DO END |
Additional reference words: 1.00 multi-thread
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |