Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4. #include <unistd.h>
  5.  
  6.  
  7. pthread_mutex_t door;
  8. void * chants(void * chants);
  9.  
  10. int main(int argc, char **argv) {
  11. srand(time(NULL));
  12. int tCount = atoi(argv[1]), i, number;
  13. //char *teams[] = {"lions", "bulldogs", "bears", "frogs", "rebels", "bulls", "seminoles", "cougars", "arrows", "jaguars"};
  14. pthread_t thread[tCount];
  15. for(i = 0;i < tCount; i++){
  16. pthread_mutex_lock(&door);
  17. number = rand()%10;
  18. pthread_create(&(thread[i]), NULL, chants,&number);
  19. pthread_mutex_unlock(&door);
  20. }
  21. pthread_exit(NULL);
  22. return 0;
  23. }
  24. void *chants(void *chants){
  25. int num = *((int *)chants);
  26. printf("%d", num);
  27. return NULL;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement