#include<
glib.
h> staticvoid
test_function(
gpointer data,
gpointer user_data) { int
i;
i =
GPOINTER_TO_INT(
data);
g_print("test function %d/n",
i); }
int
main() {
GThreadPool *
pool =NULL;
GError *error=NULL; //char data[10]="test";
int
i,
gthreadcount;
GMutex *
mutex; if(
g_thread_supported ()) printf("support g_thread/n");
g_thread_init (NULL);
mutex =
g_mutex_new();
pool =
g_thread_pool_new(
test_function,NULL,-
1,FALSE,&error); if(
pool ==NULL){
g_print("can not create thread"); }
gthreadcount =
g_thread_pool_get_num_threads(
pool);
g_print("gthread count is %d/n",
gthreadcount);
g_mutex_lock(
mutex); for(
i =
0;
i <
10 ;
i++) {
g_thread_pool_push(
pool,(
gpointer *)
i ,NULL); }
g_mutex_unlock(
mutex); // g_print("gthread count is %d/n",gthreadcount);
}
[root@localhost glib_test]# ./g_thread_pool
gthread count is 0
test function 1
test function 2
test function 3
test function 4
test function 5
test function 6
test function 7
test function 8
test function 9
gthread count is 1