+4  A: 

Are any of your variables (e.g. timeOutCNT) modified in an interrupt handler?

If so, ensure that you declare them as volatile, e.g.

volatile int timeOutCNT;

This prevents the compiler from making optimisations that assume that timeOutCNT is not modified by interrupt handlers or other threads.

Artelius
And I believe that different compilers will handle not having `volatile` there differently even with high optimizations.
nategoose
Hi Artelius,Thanks for the solution, this worked for me.Vishal N
Vishal