关于多线程的问题
上次在这里问过一个多线程的问题,已经结了
代码如下:
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <process.h>
unsigned Counter;
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
printf( "In second thread...\n" );
while ( Counter < 1000000 )
Counter++;
_endthreadex( 0 );
return 0;
}
int main()
{
HANDLE hThread;
unsigned threadID;
printf( "Creating second thread...\n" );
// Create the second thread.
hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID );
// Wait until second thread terminates. If you comment out the line
// below, Counter will not be correct because the thread has not
// terminated, and Counter most likely has not been incremented to
// 1000000 yet.
WaitForSingleObject( hThread, INFINITE );
printf( "Counter should be 1000000; it is-> %d\n", Counter );
// Destroy the thread object.
CloseHandle( hThread );
}
这个程序我在VS 2005中编译通过,能运行,但因为某些要求,现在必须在VS 2003中运行,但是VS 2003说找不到_beginthreadex和_endthreadex,请问这个两个函数是在那个头文件里面的,为什么VS 2003和VS 2005不同,多谢。
另外大家有没有用过LOG4CPLUS,这个在多线程的情况下会有问题么?