Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <pthread.h>
- #include <errno.h>
- #include <math.h>
- /* prosta funkcja wykonywana w wątku */
- void* watek(void *n) {
- int i, wynik;
- for (i=2;i<sqrt((int)n)+0.5;i++){
- if (!((int)n%i)) {
- wynik=0;
- }
- wynik=(int)n;
- }
- return (int*)wynik;
- pthread_exit((void*)wynik);
- }
- //------------------------------------------------------------------------
- #define N 5 /* liczba wątków */
- int main() {
- pthread_t id;
- int i,wynik;
- int a =2;
- pthread_create(&id, NULL, watek, &a);
- pthread_join(id,(void**)&wynik);
- printf("%d liczba pierwsza %d.\n", a, wynik);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement