I have a very complicated program that fails, and I simplified it for this test suite using a batch file and C.
My C uses ExitProcess to return the error level to a batch file. Sometimes in Windows 7 (Microsoft Windows [Version 6.1.7600]) the error level is misinterpreted.
I think this should go on forever. On Windows XP, it works forever. On two different dual-core Windows 7 machines (one 64-bit 32-bit), it crashes after a couple of minutes.
I canβt imagine that I am doing something wrong, but if there is something funny in ExTProcess on Windows 7, I thought I would ask. Is there anything here that I did illegally?
Batch file test.bat for cmd.exe:
@ECHO OFF SET I=0 :pass SET /AI=I+1 Title %I% start/wait level250 if errorlevel 251 goto fail if errorlevel 250 goto pass :fail
Program Level 250.c:
#include "windows.h" static volatile int Terminate = 0; static unsigned __stdcall TestThread(void * unused) { Terminate = 1; return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { CreateThread(NULL, 0, TestThread, NULL, 0, NULL); while (Terminate == 0) Sleep(1); ExitProcess(250); }
My version and compiler call are:
Microsoft (R) 32-bit C / C ++ Compiler Optimization version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp. 1984-1998. All rights reserved.
cl / MT level250.c
Other information: I also tried working under JPSoft TCC and getting the same behavior as using CMD. I use the direct .c program, not .cpp. I do not see failures in one version with a thread. I put the sources and binaries in http://jcook.info/win7fail and the MD5 zip file is 579F4FB15FC7C1EA454E30FDEF97C16B and the CRC32 is C27CB73D.
EDIT After making suggestions, I still changed the test case and still see the failures. There are hundreds of threads in our real application. Some threads come out with various important return codes, some run forever, and some of them freeze on operating systems or DLLs and are difficult (if not impossible) to kill.
#include "windows.h" static unsigned __stdcall TestThread(void * unused) { return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { CreateThread(NULL, 0, TestThread, NULL, 0, NULL); return(250); }