首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

GetThreadTimes有关问题!各位童鞋帮忙~

2012-06-14 
GetThreadTimes问题!各位童鞋帮忙~~~《windows核心编程》上说GetThreadTimes这个函数是获得线程时间,是这个

GetThreadTimes问题!各位童鞋帮忙~~~
《windows核心编程》上说GetThreadTimes这个函数是获得线程时间,是这个线程运行的时间么。
那位童鞋给个例子呢?我自己改写了一个,最后打印的值为1,是说这个线程的运行时间为1s 么?
#include <windows.h>
#include <stdio.h>
#include <process.h>

unsigned Counter; 
DWORD WINAPI SecondThreadFunc(PVOID pArguments )
{
  printf( "In second thread...\n" );

  while ( Counter < 1000000)
  Counter++;

  return 0;


int main()

  HANDLE hThread;
  WORD threadID;
  FILETIME hCreateTime,hExitTime,hKernelTime,hUserTime;
  printf( "Creating second thread...\n" );
  hThread = CreateThread( NULL, 0, &SecondThreadFunc, NULL, 0, NULL );
  int i=GetThreadTimes(hThread,&hCreateTime,&hExitTime,&hKernelTime,&hUserTime);
  WaitForSingleObject( hThread, INFINITE );
if(i!=0){
  printf("%d",i);
}
  printf( "Counter should be 1000000; it is-> %d\n", Counter );
  // Destroy the thread object.
  CloseHandle( hThread );
}


[解决办法]
返回值i可不是线程运行的时间,返回值是一个bool值。

BOOL WINAPI GetThreadTimes(
__in HANDLE hThread,
__out LPFILETIME lpCreationTime,
__out LPFILETIME lpExitTime,
__out LPFILETIME lpKernelTime,
__out LPFILETIME lpUserTime
);

Parameters
hThread 
A handle to the thread whose timing information is sought. This handle must have the THREAD_QUERY_INFORMATION access right. For more information, see Thread Security and Access Rights.

lpCreationTime 
A pointer to a FILETIME structure that receives the creation time of the thread.

lpExitTime 
A pointer to a FILETIME structure that receives the exit time of the thread. If the thread has not exited, the content of this structure is undefined.

lpKernelTime 
A pointer to a FILETIME structure that receives the amount of time that the thread has executed in kernel mode.

lpUserTime 
A pointer to a FILETIME structure that receives the amount of time that the thread has executed in user mode.

从msdn上拷贝下来的
[解决办法]
http://blog.csdn.net/eaglet/archive/2009/05/25/4213550.aspx
[解决办法]
int i= GetThreadTimes(hThread,&hCreateTime,&hExitTime,&hKernelTime,&hUserTime);

i是返回值,那4个xxxTime才是获得的时间

热点排行