Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct
- {
- pthread_t tid;
- int inicio;
- int fim;
- long double pi;
- } pi_struct;
- void* calcula_pi(void *args);
- int main(int argc, int * argv[])
- {
- //pi_struct *aux = (pi_struct *)args;
- struct pi_struct aux[10];
- int aux_inicio = 0;
- int aux_fim = 100;
- int counter = 2;
- int i;
- for(i = 0; i < 10; i++)
- {
- aux[i].inicio = aux_inicio;
- aux[i].fim = aux_fim;
- pthread_create(&aux[i], NULL, calcula_pi, (void*)&aux[i]);
- aux_inicio = aux_fim;
- aux_fim = aux_fim * counter;
- counter++;
- }
- printf("\nPi = %.20Lf\n", aux->pi);
- return 0;
- }
- void* calcula_pi(void *args)
- {
- double temp;
- pi_struct *aux = (pi_struct *)args;
- for(; aux->inicio < aux->fim; aux->inicio++)
- {
- temp = (pow((int)-1, (int)aux->inicio));
- aux->pi += (temp / ((2 * aux->inicio) + 1));
- }
- pthread_exit(NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement