#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<pthread.h>#include<vector>pthread_mutex_tmutex=PTHREAD_MUTEX_INITIALIZER;// 临界资源intnum=0;// 生产者void*producer(void*){inttimes=100000000;while(times--){pthread_mutex_lock(&mutex);num+=1;pthread_mutex_unlock(&mutex);}}// 消费者void*comsumer(void*){inttimes=100000000;while(times--){pthread_mutex_lock(&mutex);num-=1;pthread_mutex_unlock(&mutex);}}intmain(){printf("Start in main function.");pthread_tthread1,thread2;pthread_create(&thread1,NULL,&producer,NULL);pthread_create(&thread2,NULL,&comsumer,NULL);pthread_join(thread1,NULL);pthread_join(thread2,NULL);printf("Print in main function: num = %d\n",num);return0;}