了解 GLib 任务和上下文
Understanding GLib Task and Context
我不明白 GTask 的功能?为什么我需要这个?
在我看来,这就像回调..你在某些上下文中设置了一个源回调,然后在事件发生时调用这个回调。
总的来说,我对什么是 GLib 中的上下文和任务以及我们为什么需要它们感到有点困惑。
在我的理解中,有一个主循环(只有 1 个?)可以 运行 多个上下文(什么是上下文?)并且每个上下文都与几个源相关,而这些源又具有类似于处理程序的回调。
有人可以为我解释一下这一切吗?
I don't understand the GTask functionality? why do I need this? In my mind it is like callback.. you set a callback to a source in some context and this callback is then called when event is happening.
GTask 公开的主要功能是轻松安全地运行线程中的任务并将结果返回主线程。
In general, i'm a bit confused about what is a Context and a Task in GLib and why do we need them. In my understanding there is a main loop (only 1?) that can run several contexts (what is a context?) and each context is related to several sources which in their turn have callbacks that are like handlers.
为简单起见,我认为将上下文和循环视为同一事物是安全的,并且它们可以有多个。因此,为了线程安全,任务必须知道结果返回到哪个上下文。
我不明白 GTask 的功能?为什么我需要这个? 在我看来,这就像回调..你在某些上下文中设置了一个源回调,然后在事件发生时调用这个回调。
总的来说,我对什么是 GLib 中的上下文和任务以及我们为什么需要它们感到有点困惑。 在我的理解中,有一个主循环(只有 1 个?)可以 运行 多个上下文(什么是上下文?)并且每个上下文都与几个源相关,而这些源又具有类似于处理程序的回调。
有人可以为我解释一下这一切吗?
I don't understand the GTask functionality? why do I need this? In my mind it is like callback.. you set a callback to a source in some context and this callback is then called when event is happening.
GTask 公开的主要功能是轻松安全地运行线程中的任务并将结果返回主线程。
In general, i'm a bit confused about what is a Context and a Task in GLib and why do we need them. In my understanding there is a main loop (only 1?) that can run several contexts (what is a context?) and each context is related to several sources which in their turn have callbacks that are like handlers.
为简单起见,我认为将上下文和循环视为同一事物是安全的,并且它们可以有多个。因此,为了线程安全,任务必须知道结果返回到哪个上下文。