#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include "error.h"

pthread_t th;

void *
routine (void * arg)
{
	int ok = 0 ;

	while (ok < 4)
	{
		sleep (2);
		ok++;
	}
	return NULL;
}

/**
 Cancel thread should return PTHREAD_CANCELED as value
*/

void
main ()
{
	int status;
	void * result;

	status = pthread_create (&th, NULL, routine, NULL);
	if (status != 0)
		FAILED_ERRNO (status);


	status = pthread_cancel (th);
	if (status != 0)
		FAILED_ERRNO (status);

	status = pthread_join (th, &result);
	if (status != 0)
		FAILED_ERRNO (status);

	if (result != PTHREAD_CANCELED)
		FAILED;

	PASSED;
}
