Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #define _GNU_SOURCE
  2.  
  3. #include <unistd.h>
  4. #include <pthread.h>
  5. #include <stdlib.h>
  6. #include <sys/sysinfo.h>
  7. #include <stdio.h>
  8.  
  9. char *x;
  10.  
  11. unsigned long long arena_size = 1L * 1024 * 1024 * 1024;
  12. unsigned long long start;
  13.  
  14. void * worker(void *p) {
  15. int n;
  16. while (n<arena_size) {
  17. x[n]++;
  18. n += 4095;
  19. }
  20. }
  21.  
  22. int main( int ac, char ** av ) {
  23. int n, nthr = get_nprocs();
  24. pthread_t *threads = malloc(sizeof(pthread_t) * nthr);
  25.  
  26. x = malloc(arena_size);
  27. if (x==(caddr_t)-1) {
  28. exit(1);
  29. }
  30.  
  31. for (n=0; n<nthr; n++)
  32. pthread_create(&threads[n], NULL, worker, NULL);
  33.  
  34. while (n--)
  35. pthread_join(threads[n], NULL);
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement