#include #include int val=0; pthread_mutex_t mutex1; void* sakana(void* x){ int c=1000000; while(c--){ pthread_mutex_lock( &mutex1 ); val++; pthread_mutex_unlock( &mutex1 ); } } void* tako(void* x){ int c=1000000; while(c--){ pthread_mutex_lock( &mutex1 ); val++; pthread_mutex_unlock( &mutex1 ); } } main(){ pthread_t thre1, thre2; pthread_setconcurrency( 2 ); pthread_mutex_init( &mutex1, NULL ); pthread_create(&thre1, NULL, sakana, NULL); pthread_create(&thre2, NULL, tako, NULL); pthread_join(thre1, NULL); pthread_join(thre2, NULL); printf("val %d\n", val); }