#include <stdio.h> 
#include <stdlib.h> 
#include <windows.h> 

void work()
{
	while (1)
	{
		printf("Doing important stuff!\n");
	}
}
 
int main(int argc,char **argv) 
{ 
	DWORD id;

	if (!SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS)) 
	{
		fprintf(stderr, "cannot set priority class.\n");
	}

	HANDLE thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)work,
		NULL, CREATE_SUSPENDED, &id);

	if (!thread)
		fprintf(stderr, "cannot create thread!\n");

	int status;
	status = SetThreadPriority(thread, THREAD_PRIORITY_ABOVE_NORMAL);
	//int status = SetThreadPriority(thread, THREAD_PRIORITY_HIGHEST);
	//if (!status)
	//	fprintf(stderr,"cannot set thread's priority!\n");

	status = ResumeThread(thread);
	if (status == -1)
		fprintf(stderr,"cannot resume thread");

	WaitForSingleObject(thread, INFINITE);  // discussed later

  CloseHandle(thread);

} 
 
/*
void main()
{
  if (!SetThreadPriority(TName, THREAD_PRIORITY_BELOW_NORMAL))
  {
    std::cout<<"SetThreadPriority failed!\n";
    return false;
  }

  if ((ResumeThread(TName)) == -1)
  {
    std::cout<<"ResumeThread failed!\n";
    return false;
  }
  
  WaitForSingleObject(TName, INFINITE);  // discussed later

  CloseHandle(TName);
}

        CloseHandle(proc); 
 
        return EXIT_SUCCESS; 
} 
*/

