thread in c

时间:2015-07-15 07:24:31
【文件属性】:

文件名称:thread in c

文件大小:1KB

文件格式:CPP

更新时间:2015-07-15 07:24:31

c thread

/**内部代码*/ #include #include using namespace std; int tickets = 100; int mux1 = 0; int mux2 = 0; DWORD WINAPI func1(LPVOID lp); DWORD WINAPI func2(LPVOID lp); int main() { HANDLE h1,h2; h1 = CreateThread(NULL,0,func1,NULL,0,NULL); h2 = CreateThread(NULL,0,func2,NULL,0,NULL); Sleep(5000); CloseHandle(h1); CloseHandle(h2); cout<<"program exit...\n"; exit(0); return 0; } DWORD WINAPI func1(LPVOID lp) { while(1) { Sleep(10); mux1 = 1; if(tickets > 0) { if(!mux2) { cout<<"thread 1 sell ticket: "< 0) { if(!mux1) { cout<<"thread 2 sell ticket: "<


网友评论