Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <iostream>
- #include <cstdlib>
- #include <stdio.h>
- #include <pthread.h>
- #include <unistd.h>
- #include <errno.h>
- #include <cmath>
- using namespace std;
- void* sinus(void* arg)
- {
- double *y = (double*) arg;
- double x = *y;
- double ret = sin(x);
- sleep(pthread_self());
- cout<<"sinx = "<<ret<<endl;
- pthread_exit(0);
- return 0;
- }
- void* ln(void* arg)
- {
- double *y = (double*) arg;
- double x = *y;
- double ret = log(x);
- sleep(pthread_self());
- cout<<"lnx = "<<ret<<endl;
- pthread_exit(0);
- return 0;
- }
- void* pierw(void* arg)
- {
- double *y = (double*) arg;
- double x = *y;
- double ret = sqrt(x);
- sleep(pthread_self());
- cout<<"pierwx = "<<ret<<endl;
- pthread_exit(0);
- return 0;
- }
- int main(int argc, char **argv)
- {
- pthread_t id[2];
- double x = atof(argv[1]);
- double *tab[2];
- double suma;
- if(argc < 2 || x <= 0)
- {
- printf("Nie podano argumentu lub argument nie jest liczba dodatnia\n");
- return 0;
- }
- pthread_create(&id[1], NULL, sinus, &x);
- pthread_create(&id[2], NULL, ln, &x);
- pthread_create(&id[3], NULL, pierw, &x);
- pthread_join(id[1], (void**)&tab[0]);
- pthread_join(id[2], (void**)&tab[1]);
- pthread_join(id[3], (void**)&tab[2]);
- suma = *tab[0] + *tab[1] + *tab[2];
- cout<<"suma: "<<suma<<endl;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement