#include <stdio.h>
#include <pthread.h>

pthread_mutex_t lock;
pthread_cond_t condition;

void* waiting_thread(void* arg) {
    pthread_mutex_lock(&lock);
    printf("Waiting for signal...\n");
    pthread_cond_wait(&condition, &lock);
    printf("Received signal!\n");
    pthread_mutex_unlock(&lock);
    return NULL;
}

void* signaling_thread(void* arg) {
    pthread_mutex_lock(&lock);
    printf("Sending signal...\n");
    pthread_cond_signal(&condition);
    pthread_mutex_unlock(&lock);
    return NULL;
}

int main() {
    pthread_t thread1, thread2;
    pthread_mutex_init(&lock, NULL);
    pthread_cond_init(&condition, NULL);

    pthread_create(&thread1, NULL, waiting_thread, NULL);
    sleep(1); // Ensuring the waiting thread executes first
    pthread_create(&thread2, NULL, signaling_thread, NULL);

    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);

    pthread_mutex_destroy(&lock);
    pthread_cond_destroy(&condition);
    return 0;
}
