how to implement the WaitForMultipleObjects in linux
来源:互联网 发布:广州趣米网络 编辑:程序博客网 时间:2024/05/01 23:20
原文地址: http://www.linuxquestions.org/questions/programming-9/how-to-implement-waitformultipleobjects-in-linux-908553/
#include <stdlib.h>#include <stdio.h>#include <semaphore.h>#include <pthread.h>#include <unistd.h>#include <errno.h>#include <string.h>#define NUM_THREADS (2)sem_t semaphore;void *worker_thread(void *arg) {int i;for (i=0; i<10; ++i) {fprintf(stderr,".");sleep(1);}sem_post(&semaphore);return NULL;}int main(int argc, char* argv[]){pthread_t thread[NUM_THREADS]; int i;sem_init(&semaphore, 0, -1 * NUM_THREADS); for (i =0; i< NUM_THREADS; ++i) { pthread_create(&thread[i],NULL, &worker_thread, NULL); }if (sem_wait(&semaphore) < 0) {printf("sem_wait failed: %s\n", strerror(errno));return EXIT_FAILURE;} for (i =0; i< NUM_THREADS; ++i) { pthread_join(thread[i], NULL); } printf("\nAll threads are done now\n");return EXIT_SUCCESS;}
- how to implement the WaitForMultipleObjects in linux
- how to implement WaitForMultipleObjects in linux
- How to implement the built in effects of DirectX.DirectSound
- How to implement realtime periodic tasks in Linux applications
- How to sleep in the Linux kernel?
- HOW TO IMPLEMENT WEB SERVICES IN INDY
- How To: Implement A Server Plug-in
- How to implement Polymorphism in C
- How to implement linked controls in gridview
- How to implement master-details in OAF?
- How to Implement Ajax in WordPress Themes
- How to implement inheritance in JavaScript
- How to implement switch statement in python
- How to implement xpcom module in JavaScript
- How to implement the similar mechanism with Java final in c++?
- Java EE 6: How to implement “Stay Logged In” when user login in to the web application
- How to compile GCC-4.3.3 in the Linux?
- How to use "man" effectively in the development of Linux
- LINQ
- 线程的同步--条件变量
- sleep()和wait()的区别
- 关于ArrayList
- 分段函数
- how to implement the WaitForMultipleObjects in linux
- 模仿qq的动态列表框
- 运算符优先级
- mysql的存储过程
- Gzip 的HTTP支持(一)
- Gzip 的HTTP支持 (二)
- 尚观之webmail搭建笔记
- php内核探索方法与资源
- VS2008整合DirectX9.0开发环境