Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <pthread.h>
  4. #include <errno.h>
  5. #include <math.h>
  6.  
  7.  
  8.  
  9. /* prosta funkcja wykonywana w wątku */
  10. void* watek(void *n) {
  11. int i, wynik;
  12. for (i=2;i<sqrt((int)n)+0.5;i++){
  13. if (!((int)n%i)) {
  14. wynik=0;
  15. }
  16. wynik=(int)n;
  17. }
  18.  
  19. return (int*)wynik;
  20.  
  21. pthread_exit((void*)wynik);
  22. }
  23. //------------------------------------------------------------------------
  24.  
  25. #define N 5 /* liczba wątków */
  26.  
  27. int main() {
  28. pthread_t id;
  29. int i,wynik;
  30. int a =2;
  31.  
  32.  
  33. pthread_create(&id, NULL, watek, &a);
  34.  
  35.  
  36.  
  37. pthread_join(id,(void**)&wynik);
  38. printf("%d liczba pierwsza %d.\n", a, wynik);
  39. return EXIT_SUCCESS;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement