2 bugs:
I. this value should be other way around else, thread never sleeps (always sleep a negative number )
Original: l_lMin = elapsed_time - l_oTimer.duration;
Fix: l_lMin = l_oTimer.duration - elapsed_time;
II. m_lMinSleep = 0; is wrong, in minimum calculation, 0 or any other positive number, 0 is always be minimum, and that is why, you need to set it to max long value, or to change type to unsigned with -1 value
This value should be the other way around; thread never sleeps (always sleep a negative number):
Original:
l_lMin = elapsed_time - l_oTimer.duration;
Fix:
l_lMin = l_oTimer.duration - elapsed_time;
m_lMinSleep = 0;
is wrong. In the minimum calculation, 0 or any other positive number, 0 is always the minimum. That is why you need to set it to max long value, or change the type tounsigned
with -1 value.