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;
- double tab[3];
- void* sinus(void* arg)
- {
- double *y = (double*) arg;
- double x = *y;
- double ret = sin(x);
- tab[0]=ret;
- 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);
- tab[1]=ret;
- 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());
- tab[2]=ret;
- cout<<"pierwx = "<<ret<<endl;
- pthread_exit(0);
- return 0;
- }
- int main(int argc, char **argv)
- {
- pthread_t id[3];
- double suma=0;
- double x=0;
- if(argc < 2 || (x=atof(argv[1])) <= 0)
- {
- cout<<"Blad"<<endl;
- return 0;
- }
- pthread_create(&id[0], NULL, sinus, &x);
- pthread_create(&id[1], NULL, ln, &x);
- pthread_create(&id[2], NULL, pierw, &x);
- pthread_join(id[0], NULL);
- pthread_join(id[1], NULL);
- pthread_join(id[2], NULL);
- suma = tab[0] + tab[1] + tab[2];
- cout<<"suma: "<<suma<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement