static void *user_thread(void *unused) { int current_passenger_id = 0; pthread_t passenger_thread_handle[MAX_N_PERSONS]; for(current_passenger_id = 0; current_passenger_id < MAX_N_PERSONS; current_passenger_id++){ pthread_create(&passenger_thread_handle[current_passenger_id],NULL, passenger_thread,(void *) ¤t_passenger_id); sem_wait(&(Lift->sem)); } while(1){ sem_wait(&(Lift->sem_done)); if(all_done()){ dump_outdata(); lift_delete(Lift); int i; for(i=0; i < current_passenger_id; i++){ //pthread_join(passenger_thread_handle[i], NULL); //Why is this!!! } exit(0); } } return NULL; }
int main(int argc,char **argv) { pthread_t thread0; pthread_t thread1; pthread_attr_t attr; clock_gettime(CLOCK_MONOTONIC, &firsttime); // Start the sampling at an even multiple of a second (to make // the sample times easy to analyze by hand if necessary) firsttime.tv_sec+=2; firsttime.tv_nsec = 0; printf("Starting sampling at about t+2 seconds\n"); sem_init(&sampling_done,0,0); samples_init(&firsttime); if(pthread_attr_init(&attr)){ perror("pthread_attr_init"); } // Set default stacksize to 64 KiB (should be plenty) if(pthread_attr_setstacksize(&attr, 65536)){ perror("pthread_attr_setstacksize()"); } pthread_create(&thread0, &attr, maintask, NULL); pthread_create(&thread1, &attr, worktask, NULL); pthread_join(thread0, NULL); // Dump output data which will be used by the analyze.m script dump_outdata(); dump_sample_times(); return 0; }