GAsyncReadyCallback and cancelled GTasks


I have a question regarding GTasks and their GAsyncReadyCallback callbacks.

If a task is cancelled, it appears that the ready callback is not called. I can kind of see the reasoning here as the task is, technically, not finished it’s work successfully. However, this means that there is no callback called when the a task that is run in a thread (g_task_run_in_thread()) exits.

So, if I wanted to be able to stop a task running in a background thread and wait until that thread exists, how would I go about this? g_task_get_completed() doesn’t seem to work even though I can confirm that g_task_return_boolean is being called on the GTask.


What you describe should not happen given a proper design. It sounds like the GMainContext that the task is attached to has been discarded or is not being pumped, meaning the callback will never fire, which you have verified by get_completed never returning true.

Thanks for the hint.

The issue was that in the loop, which kept calling g_task_get_completed(), I was using g_usleep() instead of g_main_context_iteration(). With that change, I am getting the “ready” callback.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.