#include <rtl.h>
#include <time.h>
#include <rtl_sched.h>

pthread_t tasks[2];

void *hello_thr(void *arg);
void *world_thr(void *arg);

int init_module(void)
{
	pthread_create(&tasks[0], NULL, hello_thr, NULL);
	pthread_create(&tasks[1], NULL, world_thr, NULL);
	return 0;
}

void cleanup_module(void)
{
	pthread_cancel(tasks[0]);
	pthread_join(tasks[0], NULL);
	pthread_cancel(tasks[1]);
	pthread_join(tasks[1], NULL);
}

void *hello_thr(void *arg)
{
	pthread_make_periodic_np(pthread_self(), gethrtime(), 500000000);

	while(1) {
		pthread_wait_np();
		rtl_printf("Hello\n");
	}
	return 0;
}

void *world_thr(void *arg)
{
	pthread_make_periodic_np(pthread_self(), gethrtime(), 250000000);

	while(1) {
		pthread_wait_np();
		rtl_printf("World\n");
	}
	return 0;
}


