I have issue with thread-safe callbacks.
void draw_something() { /* draws something */ }
And the question is, how to call draw_something in main application thread every specify amount of time irrespective of other code(so it would act like C# Timer and fire function in main thread)? Earlier I was using CreateWindow to create(in main thread) auxiliary window which handles messages from SendMessage(which was sent from another timer-thread):
void MainThreadFunction(){
CreateThread(0, NULL, GoProc, NULL, NULL, NULL);
}
DWORD WINAPI GoProc(LPVOID lpParam){
while(1){
SendMessage(auxiliary_window_hWnd, ADDINATIONAL_MESSAGE, 0, 0);
Sleep(30);
}
return 0;
}
So window’s MessageQueue deals safethread calls, but I don’t think if it’s very efficient and elegant way to do it. I know there is better way(maybe boost?) but I don’t know it.
You can use the Windows
SetTimercall to get a periodicWM_TIMERmessage and skip the second thread altogether.