/* Bow / bow back Multi-threaded */ #include // printf #include // strcpy #include // pthread_t, pthread_create struct Friend { char name[20]; }; void initFriend(struct Friend* friend, char* name) { strcpy(friend->name, name); } void bowBack(struct Friend* bowee, struct Friend* bower) { printf("%s: I bow back to %s\n", bowee->name, bower->name); } void bow(struct Friend* bower, struct Friend* bowee) { printf("%s: I bow to %s\n", bower->name, bowee->name); bowBack(bowee, bower); } void* bowing(void* p) { struct Friend** friends = (struct Friend**)p; bow(friends[0], friends[1]); return NULL; } int main() { struct Friend alphonse; initFriend(&alphonse, "Alphonse"); struct Friend gaston; initFriend(&gaston, "Gaston"); struct Friend* ag[] = {&alphonse, &gaston}; pthread_t tid; pthread_create(&tid, NULL, bowing, (void*)ag); pthread_join(tid, NULL); fprintf(stderr, "Done\n"); }