I want to print the odd numbers in main thread and even numbers in new thread. I tried writing a program but it was only printing odd numbers not the even numbers. I tried searching for clues to find what is wrong but didn't find any.
This is my code.
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#define MAX 1000
int count = 0;
void print_odd_numbers();
void *print_even_numbers();
int main() {
pthread_t t;
int iret;
iret = pthread_create(&t, NULL, print_even_numbers, NULL);
print_odd_numbers();
pthread_join(t, NULL);
return 0;
}
void print_odd_numbers() {
while(count <= MAX) {
if(count % 2 == 1) {
printf("%d\n", count);
}
count++;
}
}
void *print_even_numbers() {
while(count <= MAX) {
if(count % 2 == 0) {
printf("%d\n", count);
}
count++;
}
pthread_exit(NULL);
}