SHARE
TWEET

lol

LazySenpai Nov 24th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <math.h>
  6.  
  7. typedef struct argument{
  8.     double n;
  9.     double k;
  10. }arg;
  11.  
  12. double newton(double n, double k) {
  13.     if(k == 0 || k == n)
  14.         return 1;
  15.     else
  16.         return newton(n-1, k-1) + newton(n-1, k);
  17. }
  18.  
  19. void* newton_use(void* _arg) {
  20.     arg *input = (arg*) _arg;
  21.     double *output = malloc(sizeof(double));
  22.     *output = newton(input->n,input->k);
  23.     pthread_exit((void*) output);
  24. }
  25.  
  26. int main(int argc, char* argv[]) {
  27.     arg input;
  28.     double *result;
  29.     input.n=atoi(argv[1]);
  30.     input.k=atoi(argv[2]);
  31.     pthread_t newton_thread;
  32.     pthread_create(&newton_thread,NULL,newton_use, &input);
  33.     while(pthread_join(newton_thread, (void**) &result) == 0 ) {
  34.         usleep(300);
  35.         printf("c\n");
  36.     }
  37.     printf("%d", *result);
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top