/* Test whether a basic pthread_cond_timedwait invocation works. */

#include <pthread.h>

#include "../basic.h"

int main(void)
{
	pthread_cond_t cnd;
	if ( (errno = pthread_cond_init(&cnd, NULL)) )
		err(1, "pthread_cond_destroy");
	pthread_mutex_t mtx;
	if ( (errno = pthread_mutex_init(&mtx, NULL)) )
		err(1, "pthread_mutex_init");
	if ( (errno = pthread_mutex_lock(&mtx)) )
		err(1, "pthread_mutex_lock");
	struct timespec short_timeout;
	clock_gettime(CLOCK_REALTIME, &short_timeout);
	if ( (errno = pthread_cond_timedwait(&cnd, &mtx, &short_timeout)) )
	{
		if ( errno != ETIMEDOUT )
			err(1, "pthread_cond_timedwait");
	}
	else
		errx(1, "pthread_cond_timedwait did not time out");
	return 0;
}
