#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
struct Array
{
//
};
void* evensum(void* param)
{
//calculated the sum of even elements and returned it
}
void* oddsum(void* param)
{
//did the same thing but for odd elements
}
int main()
{
struct Array* obj=malloc(sizeof(struct Array));
//did all the inputs
int evensum,oddsum;
pthread_t thread1,thread2;
pthread_create(&thread1,0,&evensum,(void*)obj);
int evensum,oddsum;
pthread_join(&thread,(void**)evensum);
pthread_create(&thread2,0,&oddsum,(void*)obj);
pthread_join(&thread2,(void**)oddsum);
//try to print it using %i but I get or %d
// I get the sum as zero
}
So I created two separate threads and these threads were meant to work asynchronously. I followed the advice mentioned here but the join still doesn't work as once the thread1 finishes execution, the other thread is never created despite me following the correct syntax. Any idea how to fix this? Also, the value printed is zero, despite showing the correct value if I print it in the function. Here is what I wrote in the return statement of each function:
return (void*)sum;//variable that stores sum
Also, I want to add that I don't want to use semaphores or any other synchronization tool to do this.