【多线程交替打印abcd,持续5s】一个互斥锁和条件变量的应用示例。
#include
#include
#include
#include
#includestatic int num=0;
#define THREAD_NUMBER 4
pthread_mutex_t mut_num= PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_num= PTHREAD_COND_INITIALIZER;
int next_num(int a)
{
if(a<0||a>=THREAD_NUMBER)
{
return a;
}
else if(a