Guest User

Untitled

a guest
Jul 19th, 2021
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. static int n = 32;
  7. pthread_t tid[32];
  8.  
  9. void *fnc(void *arg)
  10. {
  11. unsigned long i = 0;
  12. pthread_t id = pthread_self();
  13. int c = 0;
  14.  
  15. for(i=0; i<1024 * 64;i++) {
  16. pthread_t rid = tid[rand() % 32];
  17. if (id == rid) {
  18. c++;
  19. }
  20. }
  21. return NULL;
  22. }
  23.  
  24. int main(void)
  25. {
  26. for (int i = 0; i < n; i++)
  27. {
  28. pthread_create(&(tid[i]), NULL, &fnc, NULL);
  29. i++;
  30. }
  31. return 0;
  32. }
  33.  
RAW Paste Data