Windows 下 C/C++ 多线程编程入门参考范例

#include #include using namespace std; DWORD WINAPI myThread(LPVOID argv);//声明一个线程函数 int main(int argc, char *argv[]) { string s; HANDLE myHandle; do{ cin.clear(); cin.sync(); cin>> s; switch(s.at(0)){ case '0': myHandle = CreateThread(NULL,0,myThread,(LPVOID)s.c_str(),0,NULL);//创建线程 break; case '1': if(myHandle) SuspendThread(myHandle);//挂起线程 break; case '2': if(myHandle) ResumeThread(myHandle);//恢复线程 break; case '3': if(myHandle) TerminateThread(myHandle,0);//终止线程 break; case '4': if(myHandle) SetThreadPriority(myHandle,THREAD_PRIORITY_NORMAL);//设定线程优先级 break; default: break; } cout<< s << endl; }while(s!="exit" && s!= "quit"); return 0; } DWORD WINAPI myThread(LPVOID argv){ int i = 0; char buff[200]; ZeroMemory(buff,sizeof(buff)); memcpy(buff,argv,200); while(++i){ cout<< "Extra thread executing with argument string:"<< buff <

你可能感兴趣的:(软件与WEB)