普通任务线程池
#includeTCHAR pOutBuf[1024] = {}; #define PRINTF(...) \ StringCchPrintfW(pOutBuf,1024,__VA_ARGS__);\ WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),pOutBuf,lstrlen(pOutBuf),NULL,NULL); DWORD WINAPI ThreadPoolProc(LPVOID lparam) { long * p = (long *)lparam; while (true) { Sleep(300); CString str; InterlockedIncrement(p);//原子相加 PRINTF(_T("当前线程ID:%d 输出值:%d \n"), GetCurrentThreadId(),*p); } return 0; } int main() { int iWait = 0; wscanf_s(_T("%d"), &iWait); //创建两个线程,和CreateThread相似 QueueUserWorkItem(ThreadPoolProc, &iWait, WT_EXECUTEDELETEWAIT); QueueUserWorkItem(ThreadPoolProc, &iWait, WT_EXECUTEDELETEWAIT); getchar(); getchar(); return 0; }
网站栏目:普通任务线程池
网页链接:http://scjbc.cn/article/jeedjp.html