#include "pch.h"
#include <iostream>
#include <Windows.h>
using namespace std;

HANDLE hTimer = CreateWaitableTimer(NULL, TRUE, "tajmer");
HANDLE hTimer2 = CreateWaitableTimer(NULL, TRUE, "tajmer2");
LARGE_INTEGER liDueTime;
LARGE_INTEGER liDueTime2;


DWORD WINAPI ThreadFun(LPVOID *lpParam)
{
	liDueTime.QuadPart = -50000000LL;
	SetWaitableTimer(hTimer, &liDueTime, NULL, NULL, NULL, TRUE);
	WaitForSingleObject(hTimer, INFINITE);

	int i = 0;
	while (i < 100)
	{
		i++;
		cout << "Licznik inkrementacji watku 1 wynosi: " << i << endl;
	}

	CancelWaitableTimer(hTimer);
	return 0;
}

DWORD WINAPI ThreadFun2(LPVOID *lpParam)
{
	liDueTime2.QuadPart = -100000000LL;
	SetWaitableTimer(hTimer2, &liDueTime2, NULL, NULL, NULL, TRUE);
	WaitForSingleObject(hTimer2, INFINITE);

	int i = 0;

	while (i < 100)
	{
		i++;
		cout << "Licznik inkrementacji watku 2 wynosi: " << i << endl;
	}

	CancelWaitableTimer(hTimer2);
	return 0;
}

int main()
{
	HANDLE hThread[2];
	DWORD ThreadID1;
	DWORD ThreadID2;

	SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
	SetThreadPriority(GetCurrentThread(), -15);
	hThread[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFun, NULL, 0, &ThreadID1);
	hThread[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFun2, NULL, 0, &ThreadID2);

	SetThreadPriority(hThread[0], -15);
	SetThreadPriority(hThread[1], 15);

	WaitForMultipleObjects(2, hThread, TRUE, INFINITE);
	CloseHandle(hThread[0]);
	CloseHandle(hThread[1]);
}
