Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <unistd.h>
- pthread_mutex_t door;
- void * chants(void * chants);
- int main(int argc, char **argv) {
- srand(time(NULL));
- int tCount = atoi(argv[1]), i, number;
- //char *teams[] = {"lions", "bulldogs", "bears", "frogs", "rebels", "bulls", "seminoles", "cougars", "arrows", "jaguars"};
- pthread_t thread[tCount];
- for(i = 0;i < tCount; i++){
- pthread_mutex_lock(&door);
- number = rand()%10;
- pthread_create(&(thread[i]), NULL, chants,&number);
- pthread_mutex_unlock(&door);
- }
- pthread_exit(NULL);
- return 0;
- }
- void *chants(void *chants){
- int num = *((int *)chants);
- printf("%d", num);
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement