I am using the following code to run a function in another thread:
void load (....)
{
GIOSchedulerJob *job;
g_io_scheduler_job_send_to_mainloop(job,(GSourceFunc)job_func,¶m, g_free);
}
gboolean job_func(GIOSchedulerJob *job, GSourceFunc func, gpointer user_data, GDestroyNotify notify)
{
JobParam* job_param = (JobParam*)user_data;
build(job_param->widget, job_param->mw);
return TRUE;
}
But when I try to call g_io_scheduler_job_send_to_mainloop I get an error: g_io_scheduler_job_send_to_mainloop: assertion 'job != NULL' failed.
How can I initialize job, or can I fix the issue?
Since the is obviously related to your previous question C attempt to difference a generic pointer
I’m going to say I think you’re using the GIO job mechanism wrong (and using it for the wrong reasons as well), if you give some more detail about what you are trying to do and WHY you want to do it async someone might be able to give you a better answer, if you’re still doing the same thing in
build()you were before, that’s STILL a problem with your code, if you’re leaving things out of the code you posted, please put some comments in explaining vaguely what it would have been doing.You haven’t really given enough detail to give a proper answer. (and your code this time around seems to be LESS correct than last time)
g_io_scheduler_job_send_to_mainloop is to push a bit of work that needs to be done on the main thread, as part of a job that is already in progress, the GIOSchedulerJob is passed to your
load();by GIO when you kick of some async work withg_io_scheduler_push_job(). For example load could be something like:But fundamentally you are using the API wrong,
job_func()shouldn’t have the same type asg_io_scheduler_job_send_to_mainloop()Also this didn’t really need to be a new question, you could have edited your previous one.