I wonder if i can use channels to pass a callback (closure) to be executed in a main thread. Or should I invent my own locked queue for messages?
E.g. I have a GUI THREAD running a cycle (pseudocode):
# GUI thread -- e.g. using GetMessage() in main thread and PostThreadMessage(WM_USER) in worker thread for wakeup for Win32:
while WaitAndGetMessage(msg):
if msg.type == WakeUpAndRunCallback:
GetPostedCallBackFromQueue().execute
elif msg.type == GuiMessage:
HandleMessage(msg)
And some WORKER THREAD doing the job:
proc mythreadproc {.thread.} =
while StuffNotReady:
progress_in_percent = doNextStepOfWork()
guiThread.postCallbackToBeExecutedInGuiThread(
proc =
gui.getMyProgressBar.updateProgress(progress_in_percent) )