11程序设计实践6w-概要设计和模块化讲解.ppt

11程序设计实践6w-概要设计和模块化讲解

* * #includestdio.h #includewindows.h int tickets=100; DWORD WINAPI Fun1Proc(LPVOID pPararneter) { while(tickets0) printf(“thread1 sell ticket : %d\n”,tickets--); return 0; } DWORD WINAPI Fun2Proc(LPVOID pPararneter) { while(tickets0) printf(“thread2 sell ticket : %d\n”,tickets--); return 0; } int main() { HANDLE hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL); HANDLE hThread2=CreateThread(NULL,0,Fun2Proc,NULL,0,NULL); CloseHandle(hThread1); CloseHandle(hThread2); Sleep(4000); return 0; } * * 线程的同步 利用互斥对象(mutex)实现线程的同步,互斥对象能够确保线程拥有对单个资源的互斥访问权。 3个操作 互斥对象的创建 互斥对

文档评论(0)

1亿VIP精品文档

相关文档