- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
struct thread_arg
{
int a;
int b;
int c;
double d;
};
void *ret_x1(void *arg)
{
struct thread_arg targ = *(struct thread_arg *)arg;
double x1;
x1 = (-targ.b + sqrt(targ.d)) / (2*targ.a);
fprintf(stderr, "x1 = %f\n", x1);
return NULL;
}
void *ret_x2(void *arg)
{
struct thread_arg targ = *(struct thread_arg*)arg;
double x2;
x2 = (-targ.b - sqrt(targ.d)) / (2*targ.a);
fprintf(stderr, "x2 = %f\n", x2);
return NULL;
}
int main(void)
{
pthread_t thread1, thread2;
struct thread_arg args;
fprintf(stderr, "Enter a, b and c\n");
scanf("%d %d %d", &args.a, &args.b, &args.c);
args.d = args.b*args.b - 4*args.a*args.c;
if(args.d < 0)
{
fprintf(stderr,"There is no roots\n");
return 0;
}
else
{
if(pthread_create(&thread1, NULL, &ret_x1, &args) != 0)
{
fprintf(stderr, "Error1\n");
return 1;
}
if(pthread_create(&thread2, NULL, &ret_x2, &args) != 0)
{
fprintf(stderr, "Error2\n");
return 1;
}
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
}
return 0;
}