Untitled
unknown
plain_text
6 months ago
650 B
1
Indexable
Never
#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; }