how can use the function pthread_cond_wait to synchronize thread?
I write one example as below:

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

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <sys/uio.h>
#include <unistd.h>

pthread_t tid1,tid2;
pthread_mutex_t mutex;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

void *thread1()
while (1)
pthread_cond_wait( &cond,& mutex );
printf("\nthread1 get lock!\n");
pthread_mutex_unlock( &mutex );
sleep (5);



int main()

	pthread_mutex_init(&mutex,NULL );
	pthread_cond_init( &cond,NULL);
	sleep (60);
                            return 0;

           I want to do sleep 60s and then let thread1 runs one time,but the result is the thread runs every 5s,the condi is useless,why?

Carefully check the example in the docs against your code, you’ll find several errors.

For one thing I think your thread1 has to lock the mutex before calling pthread_cond_wait() and you’re not checking the condvar value before the the pthread_cond_wait() and pthread_cond_signal() calls.

And check your pthread return values for errors.