这个使用CreateThread创建线程写多线程的程序怎么不对啊,求解,Win32小程序

#include<stdlib.h>#include<iostream>#include<WinBase.h>usingnamespacestd;voidcal1(int... #include <stdlib.h>
#include <iostream>
#include <WinBase.h>

using namespace std;
void cal1(int);
void cal2(int);
unsigned long long themax, themin;
unsigned long long themax1, themin1;//主线程
unsigned long long themax2, themin2;//副线程

int main()
{
int times1 = 2000000;
int times2 = 3000000;
HANDLE FstThread = 0, SecThread = 0, ArrayofHandle[2];
FstThread = CreateThread(NULL, 0, cal1, ×1, 0, NULL);
SecThread = CreateThread(NULL, 0, cal2, ×2, 0, NULL);

cout << "The Max:" << (themax1 > themax2 ? themax1 : themax2) << endl
<< "The Min:" << (themin = themin1 > themin2 ? themin1 : themin2) << endl;

ArrayofHandle[0] = FstThread;
ArrayofHandle[1] = SecThread;
WaitForMultipleObjects(2, ArrayofHandle, true, INFINITE);
CloseHandle(FstThread);
CloseHandle(SecThread);
return 0;
}

void cal1(int CalTimes)
{
unsigned long long temp;
for (unsigned i = 0; i < CalTimes; i++)
{
srand(__rdtsc());
temp = rand();
if (temp > themax1)
themax1 = temp;
themin1 = themax1;
if (temp < themin1)
themin1 = themax1;
}
}

void cal2(int CalTimes)
{
unsigned long long temp;
for (unsigned i = 0; i < CalTimes; i++)
{
srand(__rdtsc());
temp = rand();
if (temp > themax2)
themax2 = temp;
themin2 = themax2;
if (temp < themin2)
themin2 = themax2;
}
}
大概就是用tsc做种子得到大量随机数,然后求其中一个最大的,一个最小的。这电脑CPU不怎么行,所以我想试试多线程的办法。程序参照网上的一个例子写的,结果会报很多行错误,都是如下的:

1>c:\program files (x86)\windows kits\8.1\include\um\minwinbase.h(251): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
字数上限了,简单说,我就是想要一个如上功能的程序,能利用CPU更多的时间片更快地得到结果
展开
 我来答
吉祥二进制
高粉答主

推荐于2016-10-05 · 科技改变生活,生活改变科技。
吉祥二进制
采纳数:33922 获赞数:84595

向TA提问 私信TA
展开全部
这代码是不是从linux平台上直接复制过来的?因为windows平台的64位大整数用的一个关键字__int64,而使用unsigned long long的好像是Linux .

其次,你的线程函数,在Windows平台上是如下的函数原型格式 :
DWORD ThreadFuncName(arg list); //线程函数的返回值不对

再次,我没有编译通过~_~ 可能是编程环境的事,因为一直用的vc6.0 还么有vs...不过,那个传递给线程函数的参数 x1 x2 你得改一下。。
追问
这个是我写的第一个程序呢。后来我发现问题出现在Winbase.h,我上网查例子,发现很多用的都是Windows.h,我改成这个头文件,华丽丽地通过并可以运行了。那个变量声明确实太冗长了,求随机数的话不需要负的,所以改成了UINT64
FEIFEI123AICAO
2014-11-07 · 超过14用户采纳过TA的回答
知道答主
回答量:31
采纳率:0%
帮助的人:32万
展开全部
回调函数的参数是void*类型吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式