How important is it to call Sleep() in a infinite while loop?

Viewed 6408

As the title says, I have a thread created using:

 CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)this->TaskProc, this, 0, NULL);

In the TaskProc, I have a an infinite while loop:

while(true)
{
// large code with lots of initialization
// get task from another thread
//  Switch (task)
// at each case you would perform a task
Sleep(1);
}

I am trying to reduce the time my code takes and I feel the Sleep(1) at the end of the while loop is not necessary! since there is quite bit of computation already done in the while loop before hitting the Sleep(), is it OK to remove the Sleep()?

EDIT1: I don't know why this question caused confusion and several down votes, this is part of a very large code with many threads (about 5), all what I wanted to know when do we have to add wait at each loop! The accepted answer seems to give a good hint on where to start. Although, I think there could be a better answer to this question.

2 Answers
Related