#include #include #include pthread_mutex_t our_mutex; void* take_a_while(void *param){ pthread_mutex_lock(&our_mutex); for(int i = 0; i < 100; i++){ printf("squash"); printf("\n"); if(i == 50){ printf("Oh no! This is bad!\n"); return 0; } } pthread_mutex_unlock(&our_mutex); /* printf("take_a_while is starting\n"); sleep(5); printf("take_a_while is ending\n"); */ return 0; } int main(){ pthread_t thread_one; pthread_create(&thread_one, 0, take_a_while, 0); for(int i = 0; i < 100; i++){ pthread_mutex_lock(&our_mutex); printf("helicopter"); printf("\n"); pthread_mutex_unlock(&our_mutex); } pthread_join(thread_one, 0); return 0; }