标签:style blog color io ar sp div 问题 on
#include <stdlib.h> #include <pthread.h> #include <stdio.h> #include <sched.h> pthread_cond_t cond; pthread_mutex_t mp; void *consumer1(void *p) { pthread_mutex_lock(&mp); printf("wait>>>(1)\n"); pthread_cond_wait(&cond, &mp); pthread_mutex_unlock(&mp); printf("wake <<<(1)\n"); return NULL; } void *consumer2(void *p) { pthread_mutex_lock(&mp); printf("wait>>>(2)\n"); pthread_cond_wait(&cond, &mp); pthread_mutex_unlock(&mp); printf("wake <<<(2)\n"); return NULL; } void *consumer3(void *p) { pthread_mutex_lock(&mp); printf("wait>>>(3)\n"); pthread_cond_wait(&cond, &mp); pthread_mutex_unlock(&mp); printf("wake <<<(3)\n"); return NULL; } int main(int argc, char *argv[]) { pthread_t t1, t2, t3; int ret; struct sched_param sched; sched.__sched_priority = 10; pthread_cond_init(&cond, NULL); pthread_mutex_init(&mp, NULL); ret = pthread_create(&t1, NULL, consumer1, NULL); ret = pthread_create(&t2, NULL, consumer2, NULL); ret = pthread_create(&t3, NULL, consumer3, NULL); sleep(1); pthread_setschedparam(t2, SCHED_FIFO, &sched); sleep(1); pthread_cond_signal(&cond); sleep(6); printf("main returned\n"); return 0; } /*当时程序在第49行出问题了,显示error: stray ‘\200’ in program 解决的办法为删除前面的空格*/
标签:style blog color io ar sp div 问题 on
原文地址:http://www.cnblogs.com/leijiangtao/p/3995843.html