如何在GTK/QT/Clutter应用程序中使用ZeroMQ? [英] How to use ZeroMQ in an GTK/QT/Clutter application?

查看:75
本文介绍了如何在GTK/QT/Clutter应用程序中使用ZeroMQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gtk 应用程序中,所有执行都在gtk_main函数内部进行.其他图形框架具有类似的事件循环,例如 QT app.exec杂波.但是, ZeroMQ 是基于以下假设:插入了while (1) ...循环(例如,请参见在此作为示例).

In gtk applications all execution is taking place inside the gtk_main function. And other graphical frame works have similar event loops like app.exec for QT and clutter_main for Clutter. However ZeroMQ is based on the assumption that there is an while (1) ... loop that it is inserted into (see for instance here for examples).

您如何结合这两种执行策略?

How do you combine those two execution strategies?

我目前想在用C语言编写的混乱应用程序中使用zeromq,所以我当然希望得到直接的答案,但也请为其他变体添加答案.

I am currently wanting to use zeromq in a clutter application written in C, so I would of course like direct answers to that, but please add answers for other variants as well.

推荐答案

这听起来像ZeroMQ代码只是希望尽可能多地反复执行.最简单的方法是将ZeroMQ代码放入空闲函数或超时函数中,并使用该函数的非阻塞版本(如果存在).

It sounds like the ZeroMQ code wants simply to be executed over and over again as often as possible. The simplest way is to put the ZeroMQ code into an idle function or timeout function, and use non-blocking versions of the functions if they exist.

对于Clutter,您可以使用 g_idle_add() g_timeout_add() .

For Clutter, you would use clutter_threads_add_idle() or clutter_threads_add_timeout(). For GTK, you would use g_idle_add() or g_timeout_add().

更困难但可能更好的方法是使用

The more difficult, but possibly better, way is to create a separate thread for the ZeroMQ code using g_thread_create(), and just use the while(1) construction with blocking functions as they suggest. If you do that, you will also have to find some way for the threads to communicate with each other - GLib's mutexes and async queues usually do fine.

这篇关于如何在GTK/QT/Clutter应用程序中使用ZeroMQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆