Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- volatile int licznik = 0;
- void *iterate1() {
- int random = rand() % 10000;
- int i;
- for(i = 0; i < random; i++) {
- printf("\n %d", i);
- licznik++;
- }
- }
- void main() {
- pthread_t thread1, thread2, thread3, thread4, thread5, thread6, thread7, thread8, thread9, thread10;
- int iret1, iret2, iret3, iret4,iret5, iret6, iret7,iret8,iret9,iret10;
- int iter = 100;
- iret1 = pthread_create( &thread1, NULL, iterate1, NULL);
- iret2 = pthread_create( &thread2, NULL, iterate1, NULL);
- iret3 = pthread_create( &thread3, NULL, iterate1, NULL);
- iret4 = pthread_create( &thread4, NULL, iterate1, NULL);
- iret5 = pthread_create( &thread5, NULL, iterate1, NULL);
- iret6 = pthread_create( &thread6, NULL, iterate1, NULL);
- iret7 = pthread_create( &thread7, NULL, iterate1, NULL);
- iret8 = pthread_create( &thread8, NULL, iterate1, NULL);
- iret9 = pthread_create( &thread9, NULL, iterate1, NULL);
- iret10 = pthread_create( &thread10, NULL, iterate1, NULL);
- pthread_join( thread1, NULL);
- pthread_join( thread2, NULL);
- pthread_join( thread3, NULL);
- pthread_join( thread4, NULL);
- pthread_join( thread5, NULL);
- pthread_join( thread6, NULL);
- pthread_join( thread7, NULL);
- pthread_join( thread8, NULL);
- pthread_join( thread9, NULL);
- pthread_join( thread10, NULL);
- printf("\n Liczba wszystkich iteracji: %d \n", licznik);
- exit(EXIT_SUCCESS);
- }
- ~
- ~
Add Comment
Please, Sign In to add comment