是否可以在GLIB循环中运行GLIB环?
只是想知道这是否可能。我一直从内部循环的一个周期/运行中得到响应。这是我的代码
struct app{
GMainContext *context;
GMainLoop *loop;
}app1;
int counter = 0;
static void
condition_responses()
{
g_print(" counter is %d \n", counter);
counter++;
}
static void
check_cmd()
{
//// other commands
if(some-condition)
{
GSource* source1 = g_timeout_source_new(1000);
// set function to watch for command to quit
g_source_set_callback(source,
(GSourceFunc)condition_responses,
NULL,
NULL);
g_source_attach(source1, app1.context);
}
}
int main()
{
GSource* source = g_timeout_source_new(1000);
// set function to watch for command to quit
g_source_set_callback(source,
(GSourceFunc)check_cmd,
NULL,
NULL);
g_source_attach(source, app1.context);
g_main_loop_run(app1.loop);
g_print("task ended \n");
}
,以某种方式运行了内部循环conditonal_respons,但它仅运行一次。我需要启动一些功能并定期运行它们。我有一个问题是
- 创建glib循环的正确方法吗?
- 我还可以做什么选择?
- 如果我创建一个g_thread去做会发生什么?
谢谢
Just wondering if this is possible. I have been getting response from one cycle/run of the inner loop. This is my code
struct app{
GMainContext *context;
GMainLoop *loop;
}app1;
int counter = 0;
static void
condition_responses()
{
g_print(" counter is %d \n", counter);
counter++;
}
static void
check_cmd()
{
//// other commands
if(some-condition)
{
GSource* source1 = g_timeout_source_new(1000);
// set function to watch for command to quit
g_source_set_callback(source,
(GSourceFunc)condition_responses,
NULL,
NULL);
g_source_attach(source1, app1.context);
}
}
int main()
{
GSource* source = g_timeout_source_new(1000);
// set function to watch for command to quit
g_source_set_callback(source,
(GSourceFunc)check_cmd,
NULL,
NULL);
g_source_attach(source, app1.context);
g_main_loop_run(app1.loop);
g_print("task ended \n");
}
Somehow the inner loop conditonal_responses run but it ran only for once.I would need to start some function and to run them periodically. Some question that I have
- Is this the right way to create the loop in glib?
- What other options could i go about doing them?
- What would happen if i create a g_thread to go about doing it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论