#include #include static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static int ready = 0; static void *producer(void *arg) { (void)arg; pthread_mutex_lock(&mtx); ready = 1; pthread_mutex_unlock(&mtx); return NULL; } static void *consumer(void *arg) { (void)arg; pthread_mutex_lock(&mtx); if (ready) { /* safe access under lock */ } pthread_mutex_unlock(&mtx); return NULL; } int main(void) { pthread_t tprod, tcons; pthread_create(&tprod, NULL, producer, NULL); pthread_create(&tcons, NULL, consumer, NULL); pthread_join(tprod, NULL); pthread_join(tcons, NULL); printf("Concurrency demo finished successfully.\n"); return 0; }