【问题标题】:Is there a function to join threads from thread pool in glib?是否有从 glib 中的线程池加入线程的功能?
【发布时间】:2021-07-20 08:58:43
【问题描述】:

这里是示例程序。

#include<glib.h>
void call_me(gpointer data, gpointer user_data)
{
    g_usleep(1);
    g_print("I am called!\n");
}
int main(int argc, char *argv[])
{
    GThreadPool* th_pool = g_thread_pool_new((GFunc)call_me, NULL, 200, TRUE, NULL);
    for(int i = 0; i < 10; ++i){
        g_thread_pool_push(th_pool, (void*)10, NULL);
    }
    return 0;
}

我认为解决方案是加入线程池中的线程,因为问题是主线程在所有线程得到时间之前返回。但是,我在 Glib 中找不到函数。如果有其他方法可以解决问题,您能否突出显示它们?

【问题讨论】:

    标签: c multithreading threadpool glib


    【解决方案1】:

    致电g_thread_pool_free (th_pool, TRUE, TRUE)。它将等待所有挂起的任务完成运行,然后释放GThreadPool 使用的内存。

    【讨论】:

      猜你喜欢
      • 2015-07-26
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      • 1970-01-01
      • 2016-09-26
      • 2017-08-06
      相关资源
      最近更新 更多