#include #include int val=0; void* sakana(void* x){ int c=1000000; while(c--){ int lval; //printf("%s\n", "sakana"); lval=val; lval++; val=lval; //usleep(random()%1010); } } void* tako(void* x){ int c=1000000; while(c--){ int lval; //printf("%s\n", "tako"); lval=val; lval++; val=lval; //usleep(random()%1000); } } main(){ pthread_t thre1, thre2; pthread_setconcurrency( 2 ); 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); }