标签:线程
#include <stdio.h>
#include <process.h>
#include <Windows.h>
class CUser
{
public:
HANDLE m_hThr;
void Suppend()
{
SuspendThread(m_hThr);
}
};
unsigned _stdcall ThrTest(VOID* pPara)
{
CUser* p = (CUser*)pPara;
int a = 0;
while(1)
{
printf("Send email success -> %d\n", ++a);
// 自陷如暂停状态
p->Suppend();
}
return 0;
}
int main()
{
CUser* p = new CUser();
// 创建发邮件线程,创建时挂起
p->m_hThr = (HANDLE)_beginthreadex(NULL, 0, ThrTest, p, CREATE_SUSPENDED, NULL);
while(1)
{
// 需要启动线程
ResumeThread(p->m_hThr);
Sleep(1500);
}
CloseHandle(p->m_hThr);
delete p;
p = NULL;
return 0;
}一种线程调度策略【线程需要的时候运行,不需要的时候暂停】,布布扣,bubuko.com
标签:线程
原文地址:http://blog.csdn.net/arbboter/article/details/38314513