glib 线程池 thread_pool
来源:互联网 发布:java基础笔试题 编辑:程序博客网 时间:2024/05/16 17:23
#include <stdio.h>#include <glib.h>#include <string.h>/** 全局锁*/GMutex g_lock;#define MAX_THREAD_NUM 10/** * @brief 线程池回调函数,线程执行的主体函数 */void show_result(gpointer str, gpointer data){ g_mutex_lock(&g_lock); printf("The result is : %s\n", (char*)str); g_mutex_unlock(&g_lock); if(1) { g_printf("thread[%lu] is running...\n",pthread_self()); sleep(10); }}int main(){ char *str = "thread_pool example"; int count = 0; int g_thread_num = 0; GThreadPool *thread_pool; /** * 初始化互斥锁,NULL表示使用默认的快速互斥锁。 */ g_mutex_init(&g_lock); thread_pool = g_thread_pool_new(show_result, NULL, MAX_THREAD_NUM, TRUE, NULL); if (thread_pool == NULL) { printf("g_thread_pool_new failed!\n"); return -1; } /** * 调用20次线程池 * 实际线程池中最多有10个线程同时运行 */ for (count; count < 20; count++) { g_thread_pool_push(thread_pool, (gpointer)str, NULL); } g_thread_num = g_thread_pool_get_max_threads(thread_pool); printf("Max number in the pthread pool: %d\n", g_thread_num); g_thread_pool_free(thread_pool, 0, 1); return;}
0 0
- glib 线程池 thread_pool
- C 线程池 thread_pool
- C++ 简单的线程池 thread_pool
- glib的线程池
- thread_pool
- glib中线程池的实现学习
- glib库线程池代码分析
- glib学习笔记之四——GLib核心应用支持:glib库线程池代码分析
- glib库异步队列和线程池代码分析
- glib库异步队列和线程池代码分析
- glib库异步队列和线程池代码分析
- glib库异步队列和线程池代码分析
- glib
- GLib
- Glib
- glib
- glib
- 关于glib中的线程demo之一
- linux gcc
- margin在文档流和浮动中的区别
- 如何让新员工快速成长
- HDU 1109
- angular的$watch 函数
- glib 线程池 thread_pool
- java office文档转pdf
- 下标的使用和运算符重载
- java.lang.IllegalArgumentException: Malformed \uxxxx encoding.解决方法
- Android动画
- MFC删除文件夹
- linux定时执行任务
- 断点调试express
- Error:Could not determine the dependencies of task ':app:transformClassesWithInstantRunForDebug'.