今天有人问我windows xp时间片是多少。想了一会没想起来。索性就写了段代码。
注:是在虚拟机里单核CPU里跑的。
#include <windows.h>
#include <iostream.h>DWORD WINAPI Fun1Proc(LPVOID lpParameter);
int index = 0;void main()
{
HANDLE hThread1;
hThread1 = CreateThread(NULL, 0, Fun1Proc, NULL, 0, NULL);
CloseHandle(hThread1);
cout << "Main thread is running!" << endl;
Sleep(1000);
cout << index << endl;
cout << "Main Thread finished!" << endl;
}//线程1的入口函数
DWORD WINAPI Fun1Proc(LPVOID lpParameter)
{
while (index++ < 1000)
cout << "Thread1 is running!" << endl;
return 0;
}
思路:建立两个线程,一个主一个从。然后调用Sleep函数让主线程暂停1s,执行从进程。最后打印输出。粗略的计算了下每次线程调用的时间大概是5ms左右。
大家看看这个思路是否可行。
注:是在虚拟机里单核CPU里跑的。
#include <windows.h>
#include <iostream.h>DWORD WINAPI Fun1Proc(LPVOID lpParameter);
int index = 0;void main()
{
HANDLE hThread1;
hThread1 = CreateThread(NULL, 0, Fun1Proc, NULL, 0, NULL);
CloseHandle(hThread1);
cout << "Main thread is running!" << endl;
Sleep(1000);
cout << index << endl;
cout << "Main Thread finished!" << endl;
}//线程1的入口函数
DWORD WINAPI Fun1Proc(LPVOID lpParameter)
{
while (index++ < 1000)
cout << "Thread1 is running!" << endl;
return 0;
}
思路:建立两个线程,一个主一个从。然后调用Sleep函数让主线程暂停1s,执行从进程。最后打印输出。粗略的计算了下每次线程调用的时间大概是5ms左右。
大家看看这个思路是否可行。
解决方案 »
- VC2005窗体默认颜色
- 物体移动,事件怎么没有实现,高手进来看看~!
- 如何隐藏IE窗口?ShellExecute中的SW_HIDE参数为什么不起作用?
- 我将excel中的文字拷入txt文件中,用CFile打开,怎么出现乱码,谁有解决的源代码,100分送
- 如何调用invalidate()来启动onpaint()刷新,我这样做对吗?
- 怎样将英文版本改为中文版本啊!
- AppWizard 没有选择打印和打印欲览支持,后来想要,怎么办呢??
- 为什么D版的Vc++6.0安装不起,紧急!!
- VC方面的GIS大虾!请进!!!!!!
- 谁能告诉我:没有学位证书影响大吗?
- 急 请教ClistCtrl的问题
- HOOK截获中文输入会出现响应多次的情况,即重复输出两次的情况。
cout,endl花的时间太多,在输出到控制台时还会导致放弃当前时间片
http://hi.baidu.com/skrapp/blog/item/9ba3314c27af9ffad72afc9b.html