点击(此处)折叠或打开
- // gcc -lpthread server.c -o server
- // indent -npro -kr -i8 -ts8 -sob -l280 -ss -ncs -cp1 *
- #include <pthread.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <poll.h>
-
- void *thread(void *arg)
- {
- int i = 0;
- do {
- struct pollfd f;
- f.fd = 0;
- f.events = POLLPRI;
- poll(&f, 1, 10);
- i++;
- } while (i < 100);
- return NULL;
- }
-
- #define CNT 5
-
- int main()
- {
- void *res;
- int i;
- pthread_t t[CNT];
- do {
- printf("New\n");
- for (i = 0; i < CNT; i++)
- pthread_create(&t[i], NULL, thread, 0);
- printf("Stop\n");
- for (i = 0; i < CNT; i++) {
- pthread_cancel(t[i]);
- pthread_join(t[i], &res);
- pthread_create(&t[i], NULL, thread, 0);
- }
- } while (1);
- return 0;
- }
相关热门文章
给主人留下些什么吧!~~
评论热议