Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341218
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:08:00

我在VC 建立了Win32 Appication工程 ,程序如下:

#include
#include
#include
#include
#include
#include

class CmyEvent
{
private:
HANDLE m_hEvent;
public:
//constructor
CmyEvent(BOOL bAuto,char* EventName);

//impleation
//wait for a event
unsigned long WaitForEvent(double time);
//set a event
BOOL Signal();
//reset a event
BOOL Reset();
//pulse a event
BOOL Pulse();
//check the state of a event
BOOL IsSignaled();
};

CmyEvent:: CmyEvent(BOOL bAuto,char* EventName)
{
m_hEvent=::CreateEvent(NULL,bAuto,FALSE,NULL);
// if(NULL==m_hEvent)
// AfxMessageBox("Fail");
}

unsigned long CmyEvent::WaitForEvent(double time)
{
return ::WaitForSingleObject(m_hEvent,(DWORD)time);
}

BOOL CmyEvent::Signal()
{
return ::SetEvent(m_hEvent);
}

BOOL CmyEvent::Reset()
{
return ::ResetEvent(m_hEvent);
}

BOOL CmyEvent::Pulse()
{
return ::PulseEvent(m_hEvent);
}

/*
BOOL CmyEvent::Pulse()
{
::SetEvent(m_hEvent);
::Sleep(100);
::ResetEvent(m_hEvent);

return TRUE;
}
*/
BOOL CmyEvent::IsSignaled()
{
BOOL flag=false;
if(::WaitForSingleObject(m_hEvent,0)==WAIT_OBJECT_0)
flag=true;
}

CmyEvent Myevent(TRUE,"MYEVENT");
int array[5];

void MyThread1(void* arg)
{
Sleep(2000);
for(int i=0;i<5;i++)
array[i]=i;

cout<<"Data are ready.Signal an event!"< Myevent.Signal();
}

void MyThread2(void* arg)
{
cout<<"Data are ready.Get signaled!"< for(int i=0;i<5;i++)
cout<}

int main(int argc, char* argv[])
{
_beginthread(MyThread1,0,NULL);
_beginthread(MyThread2,0,NULL);
Sleep(6000);
return 0;

}


可是编译时说:D:\VC\Demo\demo.cpp(95) : error C2065: '_beginthread' : undeclared identifier

可是_beginthread是windows 的API函数啊,怎么会是undeclared identifier
呢?

--------------------next---------------------

阅读(1600) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~