multithreading - Windows Multi Timer: Why Timer callback function execute time-out can cause another timer became mess? (deep in Timer implementation mechanism ) -
here source code:
#include <windows.h> #include <iostream> using namespace std; #pragma comment(lib, "winmm.lib") uint videotimerid; uint audiotimeid; static void callback onvideotimer( uint utimerid, uint umsg, dword_ptr dwuser, dword_ptr dw1, dword_ptr dw2 ) { cout << "[video-timer] systemtime: " << timegettime() << endl; sleep(30); } static void callback onaudiotimer( uint utimerid, uint umsg, dword_ptr dwuser, dword_ptr dw1, dword_ptr dw2 ) { cout << "----[audio-timer] systemtime: " << timegettime() << endl; } int main() { timebeginperiod(1); videotimerid = timesetevent(40, 1, onvideotimer, null, time_periodic); audiotimeid = timesetevent(128, 1, onaudiotimer, null, time_periodic); while (1); return 0; }
in case, ok. output is:
[video-timer] systemtime: 10705911 [video-timer] systemtime: 10705951 [video-timer] systemtime: 10705991 ----[audio-timer] systemtime: 10706023 [video-timer] systemtime: 10706031 [video-timer] systemtime: 10706071 [video-timer] systemtime: 10706111 ----[audio-timer] systemtime: 10706143 [video-timer] systemtime: 10706151 [video-timer] systemtime: 10706191 [video-timer] systemtime: 10706231 ----[audio-timer] systemtime: 10706263 [video-timer] systemtime: 10706271 [video-timer] systemtime: 10706311 [video-timer] systemtime: 10706351 ----[audio-timer] systemtime: 10706383 [video-timer] systemtime: 10706391 [video-timer] systemtime: 10706431 [video-timer] systemtime: 10706471 ----[audio-timer] systemtime: 10706511 [video-timer] systemtime: 10706513 [video-timer] systemtime: 10706551 [video-timer] systemtime: 10706591 [video-timer] systemtime: 10706631 ----[audio-timer] systemtime: 10706663
but after change sleep(30) sleep(50), output becomes messy.
[video-timer] systemtime: 11018552 [video-timer] systemtime: 11018605 [video-timer] systemtime: 11018657 [video-timer] systemtime: 11018709 [video-timer] systemtime: 11018761 [video-timer] systemtime: 11018813 [video-timer] systemtime: 11018866 [video-timer] systemtime: 11018918 [video-timer] systemtime: 11018970 [video-timer] systemtime: 11019023 [video-timer] systemtime: 11019075 [video-timer] systemtime: 11019127 [video-timer] systemtime: 11019179 [video-timer] systemtime: 11019231 [video-timer] systemtime: 11019284 [video-timer] systemtime: 11019336 [video-timer] systemtime: 11019391 [video-timer] systemtime: 11019443 [video-timer] systemtime: 11019495 [video-timer] systemtime: 11019547 [video-timer] systemtime: 11019599 [video-timer] systemtime: 11019651 [video-timer] systemtime: 11019703 [video-timer] systemtime: 11019755 [video-timer] systemtime: 11019807
and audio-timer callback function never executed.
why video-timer callback function executed time-out can affect audio-timer?
what implementation mechanism of timer?
the question come real project:
sometimes, video-timer callback function takes more 40ms, in situation, timesetevent() me or other choices can take?
any appreciated.
Comments
Post a Comment