解决方案 »
- SetViewportOrg()和BeginPath()、EndPath()会产生冲突
- SetWindowsHookEx调用的是哪个内核函数?
- 模式对话框发送消息的问题
- CMarkup解析xml
- 关于OnEraseBkgnd的问题
- 请问如何判断是否安装了EXCEL2003
- 如何获取一个纯英文字符文本文件中某个特定字符串的个数?
- 关于参数传递的问题,请赐教!
- char* 的问题!
- SetWindowExt 和 SetViewportExt的问题
- 跪求 录音程序动态库 源代码!可以改变录音时的参数比如,抽取率,8位或者16位.
- 终于明白为什么在父窗口的wm_paint 中无法对子控件进行进行gdi操作了
{
cout<<"thread is doing"<<endl;
return 1;
}
#include <windows.h>
#include <process.h>
using namespace std;
Event fevent;//事件
int data=0;//参数
bool flag=1;
unsigned int __stdcall f(void *);//线程调用的函数 bool flag=true;
int main() {
cout<<"this is main before thread"<<endl;
HANDLE hth1;
hth1 = (HANDLE)_beginthreadex( NULL, //创建线程
0,
f,
data,//参数
CREATE_SUSPENDED,
NULL);
ResumeThread(hth1);
while(1){
data=999;//根据需要改变参数,分配任务
SetEvent(fevent);
} flag=0;//终止线程。
WaitForSingleObject(hth1,INFINITE);//等待线程结束
cout<<"this is main after thread"<<endl;
CloseHandle(hth1);
return 0;
}
unsigned int __stdcall f(void *)
{
while(flag)
{
WaitForSingleObject(fevent,INFINITE);//等待主线程通知;
cout<<"thread is doing"<<endl;
Sleep(1000);
}
return 1;
}
错误如下:Compiling...
tets.cpp
e:\vctest\thread_5\tets.cpp(6) : error C2146: syntax error : missing ';' before identifier 'fevent'
e:\vctest\thread_5\tets.cpp(6) : error C2501: 'Event' : missing storage-class or type specifiers
e:\vctest\thread_5\tets.cpp(6) : fatal error C1004: unexpected end of file found
Error executing cl.exe.thread_5.exe - 3 error(s), 0 warning(s)
flag感觉多余另外:flag明显错误, 多个线程操作 变量flag.显然不对幸亏是一汇编指令。
http://hi.baidu.com/jimoguilai2012/item/b78b2ff60efde90cc6dc45dc
fevent.SetEvent(); //改为CEvent后用成员函数
Sleep(2000);//2秒检查一次,避免占用cpu }