Software: Apache/2.0.54 (Fedora). PHP/5.0.4 uname -a: Linux mina-info.me 2.6.17-1.2142_FC4smp #1 SMP Tue Jul 11 22:57:02 EDT 2006 i686 uid=48(apache) gid=48(apache) groups=48(apache) Safe-mode: OFF (not secure) /usr/share/gtk-doc/html/glib/ drwxr-xr-x |
Viewing file: Select action/file-type:
Synopsis#include <glib.h> GThreadPool; GThreadPool* g_thread_pool_new (GFunc func, gpointer user_data, gint max_threads, gboolean exclusive, GError **error); void g_thread_pool_push (GThreadPool *pool, gpointer data, GError **error); void g_thread_pool_set_max_threads (GThreadPool *pool, gint max_threads, GError **error); gint g_thread_pool_get_max_threads (GThreadPool *pool); guint g_thread_pool_get_num_threads (GThreadPool *pool); guint g_thread_pool_unprocessed (GThreadPool *pool); void g_thread_pool_free (GThreadPool *pool, gboolean immediate, gboolean wait); void g_thread_pool_set_max_unused_threads (gint max_threads); gint g_thread_pool_get_max_unused_threads (void); guint g_thread_pool_get_num_unused_threads (void); void g_thread_pool_stop_unused_threads (void); DescriptionSometimes you wish to asyncronously fork out the execution of work and continue working in your own thread. If that will happen often, the overhead of starting and destroying a thread each time might be to high. In such cases reusing already started threads seems like a good idea. And it indeed is, but implementing this can be tedious and error-prone. Therefore GLib provides thread pools for your convenience. An added advantage is, that the threads can be shared between the different subsystems of your program, when they are using GLib.
To create a new thread pool, you use
If you want to execute a certain task within a thread pool, you call
To get the current number of running threads you call
Finally you can control the number of unused threads, that are kept
alive by GLib for future use. The current number can be fetched with
DetailsGThreadPooltypedef struct { GFunc func; gpointer user_data; gboolean exclusive; } GThreadPool; The GThreadPool struct represents a thread pool. It has six public read-only members, but the underlying struct is bigger, so you must not copy this struct. g_thread_pool_new ()GThreadPool* g_thread_pool_new (GFunc func, gpointer user_data, gint max_threads, gboolean exclusive, GError **error); This function creates a new thread pool.
Whenever you call
The parameter
g_thread_pool_push ()void g_thread_pool_push (GThreadPool *pool, gpointer data, GError **error);
Inserts
g_thread_pool_set_max_threads ()void g_thread_pool_set_max_threads (GThreadPool *pool, gint max_threads, GError **error);
Sets the maximal allowed number of threads for
Setting
A thread is never terminated while calling
g_thread_pool_get_max_threads ()gint g_thread_pool_get_max_threads (GThreadPool *pool);
Returns the maximal number of threads for
g_thread_pool_get_num_threads ()guint g_thread_pool_get_num_threads (GThreadPool *pool);
Returns the number of threads currently running in
g_thread_pool_unprocessed ()guint g_thread_pool_unprocessed (GThreadPool *pool);
Returns the number of tasks still unprocessed in
g_thread_pool_free ()void g_thread_pool_free (GThreadPool *pool, gboolean immediate, gboolean wait);
Frees all resources allocated for
If
If
After calling this function
g_thread_pool_set_max_unused_threads ()void g_thread_pool_set_max_unused_threads (gint max_threads);
Sets the maximal number of unused threads to
g_thread_pool_get_max_unused_threads ()gint g_thread_pool_get_max_unused_threads (void); Returns the maximal allowed number of unused threads.
g_thread_pool_get_num_unused_threads ()guint g_thread_pool_get_num_unused_threads (void); Returns the number of currently unused threads.
g_thread_pool_stop_unused_threads ()void g_thread_pool_stop_unused_threads (void);
Stops all currently unused threads. This does not change the
maximal number of unused threads. This function can be used to
regularly stop all unused threads e.g. from
|
:: Command execute :: | |
--[ c99shell v. 1.0 pre-release build #16 powered by Captain Crunch Security Team | http://ccteam.ru | Generation time: 0.0049 ]-- |