Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
650 B
2
Indexable
#include <stdio.h>
#include <pthread.h>

#define MAX_NUMBER 10

void *printOdd(void *args) {
    for (int i = 1; i <= MAX_NUMBER; i += 2) {
        printf("Odd: %d\n", i);
    }

    pthread_exit(NULL);
}

void *printEven(void *args) {
    for (int i = 2; i <= MAX_NUMBER; i += 2) {
        printf("Even: %d\n", i);
    }

    pthread_exit(NULL);
}

int main() {
    pthread_t thread1, thread2;

    // Create two threads
    pthread_create(&thread1, NULL, printOdd, NULL);
    pthread_create(&thread2, NULL, printEven, NULL);

    // Wait for both threads to finish
    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);

    return 0;
}