首页 > 代码库 > thread_8

thread_8

#include <stdlib.h>  #include <pthread.h>  #include <stdio.h> #include <sched.h>   void *consumer(void *p) {         int i;        printf("start (%d)\n", (int)p);          for (i = 0; 1; i++)        {                sleep(1);                printf("<<<<<<<<<<<<<<<<<<<<<wake(%d)\n", (int)p);          } } int main(int argc, char *argv[]) {         pthread_t  t1, t2, t3;         struct sched_param sched3, sched4;        sched3.__sched_priority = 70;          int policy;         pthread_create(&t1, NULL, consumer, (void *)4);          pthread_create(&t2, NULL, consumer, (void *)5);        pthread_create(&t3, NULL, (consumer), (void *)6);         sleep(4);        pthread_setschedparam(t3, SCHED_FIFO, &sched3);         printf("main run\n");        pthread_getschedparam(t3, &policy, &sched4);        printf("policy: %d, priority: %d\n", policy, sched4.__sched_priority);         exit(1);         pthread_join(t1, NULL);         pthread_join(t2, NULL);        pthread_join(t3, NULL);     return 0; }

 

thread_8