I am trying to write a C program which involves threads. The user inputs a number and a thread is created to compute the sin value for that number. Right now when I compile and run the code the thread never seems to terminate. I have also included the steps I am using to compile this program in the comments in my source code.
#include <stdio.h>
#include <math.h>
#include <pthread.h>
/*
compile:
1. gcc MyName.c -o MyName -lm -lpthread
2. ./MyName.c
*/
double result;
double x;
void *calcSin(void *u);
int main()
{
pthread_t tid;
pthread_attr_t attr;
pthread_attr_init(&attr); //Set thread attributes
pthread_create(&tid, &attr, calcSin, NULL); //Create thread
pthread_join(tid,NULL); //Wait until new thread completes
printf("First thread completed here is sin: %lf\n", result);
return 0;
}
void *calcSin(void *u)
{
result = 0;
printf("Enter first number: \n");
scanf("%lf\n",&x);
result = sin(x);
pthread_exit(0);
}