#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<pthread.h>#include<vector>pthread_spinlock_tspin_lock;intnum=0;void*producer(void*){inttimes=10000000;while(times--){pthread_spin_lock(&spin_lock);num+=1;pthread_spin_unlock(&spin_lock);}}void*comsumer(void*){inttimes=10000000;while(times--){pthread_spin_lock(&spin_lock);num-=1;sleep(10);pthread_spin_unlock(&spin_lock);}}intmain(){printf("Start in main function.\n");pthread_spin_init(&spin_lock,0);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;}