<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Glib::ThreadPool class Reference</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#ffffff"> <table border="0" width="100%"> <tr> <td width="10%" height="40"><img src="../../images/gtkmm_logo.gif" alt="logo" border="0" width="100%" height="100%"/></td> <td width="90%" height="40"><img src="../../images/top.gif" alt="top" width="100%" height="40"/></td> </tr> </table> <center> <a class="qindex" href="../../index.html">Main Page</a> <a href="group__Widgets.html">Widgets</a> <a class="qindex" href="namespaces.html"> Namespaces</a> <a href="../../tutorial/html/index.html"> Book</a> </center> <hr width="100%"/> <!-- Generated by Doxygen 1.3-rc1 --> <h1>Glib::ThreadPool Class Reference<br> <small> [<a class="el" href="group__ThreadPools.html">Thread Pools</a>]</small> </h1>A pool of threads to execute work concurrently. <a href="#_details">More...</a> <p> <a href="classGlib_1_1ThreadPool-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0> <tr><td></td></tr> <tr><td colspan=2><br><h2>Public Methods</h2></td></tr> <tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a0">ThreadPool</a> (int max_threads=-1, bool exclusive=false)</td></tr> <tr><td> </td><td><font size=-1><em>Constructs a new thread pool.</em> <a href="#a0"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>virtual </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a1">~ThreadPool</a> ()</td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a2">push</a> (const SigC::Slot0<void>& slot)</td></tr> <tr><td> </td><td><font size=-1><em>Inserts <em>slot</em> into the list of tasks to be executed by the pool.</em> <a href="#a2"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a3">set_max_threads</a> (int max_threads)</td></tr> <tr><td> </td><td><font size=-1><em>Sets the maximal allowed number of threads for the pool.</em> <a href="#a3"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a4">get_max_threads</a> () const</td></tr> <tr><td> </td><td><font size=-1><em>Returns the maximal number of threads for the pool.</em> <a href="#a4"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>unsigned int </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a5">get_num_threads</a> () const</td></tr> <tr><td> </td><td><font size=-1><em>Returns the number of threads currently running in the pool.</em> <a href="#a5"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>unsigned int </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a6">unprocessed</a> () const</td></tr> <tr><td> </td><td><font size=-1><em>Returns the number of tasks still unprocessed in the pool.</em> <a href="#a6"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>bool </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a7">get_exclusive</a> () const</td></tr> <tr><td> </td><td><font size=-1><em>Returns whether all threads are exclusive to this pool.</em> <a href="#a7"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a8">shutdown</a> (bool immediately=false)</td></tr> <tr><td> </td><td><font size=-1><em>Frees all resources allocated for the pool.</em> <a href="#a8"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a class="el" href="threadpool_8h.html#a0">GThreadPool</a>* </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a9">gobj</a> ()</td></tr> <tr><td nowrap align=right valign=top>const <a class="el" href="threadpool_8h.html#a0">GThreadPool</a>* </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#a10">gobj</a> () const</td></tr> <tr><td colspan=2><br><h2>Static Public Methods</h2></td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#d0">set_max_unused_threads</a> (int max_threads)</td></tr> <tr><td> </td><td><font size=-1><em>Sets the maximal number of unused threads to <em>max_threads.</em> </em> <a href="#d0"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#d1">get_max_unused_threads</a> ()</td></tr> <tr><td> </td><td><font size=-1><em>Returns the maximal allowed number of unused threads.</em> <a href="#d1"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>unsigned int </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#d2">get_num_unused_threads</a> ()</td></tr> <tr><td> </td><td><font size=-1><em>Returns the number of currently unused threads.</em> <a href="#d2"></a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="classGlib_1_1ThreadPool.html#d3">stop_unused_threads</a> ()</td></tr> <tr><td> </td><td><font size=-1><em>Stops all currently unused threads.</em> <a href="#d3"></a><em></em></font><br><br></td></tr> </table> <hr><a name="_details"></a><h2>Detailed Description</h2> A pool of threads to execute work concurrently. <p> <hr><h2>Constructor & Destructor Documentation</h2> <a name="a0" doxytag="Glib::ThreadPool::ThreadPool"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> Glib::ThreadPool::ThreadPool </td> <td class="md" valign="top">(</td> <td class="md" nowrap valign="top">int </td> <td class="mdname" nowrap> <em>max_threads</em> = -1, </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap>bool </td> <td class="mdname" nowrap> <em>exclusive</em> = false</td> </tr> <tr> <td></td> <td class="md">) </td> <td class="md" colspan="2"><code> [explicit]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Constructs a new thread pool. <p> Whenever you call <a class="el" href="classGlib_1_1ThreadPool.html#a2">ThreadPool::push()</a>, either a new thread is created or an unused one is reused. At most <em>max_threads</em> threads are running concurrently for this thread pool. <em>max_threads = -1</em> allows unlimited threads to be created for this thread pool. <p> The parameter <em>exclusive</em> determines, whether the thread pool owns all threads exclusive or whether the threads are shared globally. If <em>exclusive</em> is <code>true</code>, <em>max_threads</em> threads are started immediately and they will run exclusively for this thread pool until it is destroyed by <a class="el" href="classGlib_1_1ThreadPool.html#a1">~ThreadPool()</a>. If <em>exclusive</em> is <code>false</code>, threads are created when needed and shared between all non-exclusive thread pools. This implies that <em>max_threads</em> may not be -1 for exclusive thread pools. <p> <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>max_threads</em> </td><td>The maximal number of threads to execute concurrently in the new thread pool, -1 means no limit. </td></tr> <tr><td valign=top><em>exclusive</em> </td><td>Should this thread pool be exclusive? </td></tr> </table> </dl> <dl compact><dt><b>Exceptions:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>Glib::ThreadError</em> </td><td>An error can only occur when <em>exclusive</em> is set to <code>true</code> and not all <em>max_threads</em> threads could be created. </td></tr> </table> </dl> </td> </tr> </table> <a name="a1" doxytag="Glib::ThreadPool::~ThreadPool"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> virtual Glib::ThreadPool::~ThreadPool </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap><code> [virtual]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> </td> </tr> </table> <hr><h2>Member Function Documentation</h2> <a name="a7" doxytag="Glib::ThreadPool::get_exclusive"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> bool Glib::ThreadPool::get_exclusive </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap> const</td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Returns whether all threads are exclusive to this pool. <p> <dl compact><dt><b>Returns:</b></dt><dd>Whether all threads are exclusive to this pool. </dd></dl> </td> </tr> </table> <a name="a4" doxytag="Glib::ThreadPool::get_max_threads"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> int Glib::ThreadPool::get_max_threads </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap> const</td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Returns the maximal number of threads for the pool. <p> <dl compact><dt><b>Returns:</b></dt><dd>The maximal number of threads. </dd></dl> </td> </tr> </table> <a name="d1" doxytag="Glib::ThreadPool::get_max_unused_threads"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> int Glib::ThreadPool::get_max_unused_threads </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap><code> [static]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Returns the maximal allowed number of unused threads. <p> <dl compact><dt><b>Returns:</b></dt><dd>The maximal number of unused threads. </dd></dl> </td> </tr> </table> <a name="a5" doxytag="Glib::ThreadPool::get_num_threads"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> unsigned int Glib::ThreadPool::get_num_threads </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap> const</td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Returns the number of threads currently running in the pool. <p> <dl compact><dt><b>Returns:</b></dt><dd>The number of threads currently running. </dd></dl> </td> </tr> </table> <a name="d2" doxytag="Glib::ThreadPool::get_num_unused_threads"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> unsigned int Glib::ThreadPool::get_num_unused_threads </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap><code> [static]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Returns the number of currently unused threads. <p> <dl compact><dt><b>Returns:</b></dt><dd>The number of currently unused threads. </dd></dl> </td> </tr> </table> <a name="a10" doxytag="Glib::ThreadPool::gobj"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> const <a class="el" href="threadpool_8h.html#a0">GThreadPool</a>* Glib::ThreadPool::gobj </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap> const<code> [inline]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> </td> </tr> </table> <a name="a9" doxytag="Glib::ThreadPool::gobj"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> <a class="el" href="threadpool_8h.html#a0">GThreadPool</a>* Glib::ThreadPool::gobj </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap><code> [inline]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> </td> </tr> </table> <a name="a2" doxytag="Glib::ThreadPool::push"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void Glib::ThreadPool::push </td> <td class="md" valign="top">(</td> <td class="md" nowrap valign="top">const SigC::Slot0<void>& </td> <td class="mdname1" valign="top" nowrap> <em>slot</em> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Inserts <em>slot</em> into the list of tasks to be executed by the pool. <p> When the number of currently running threads is lower than the maximal allowed number of threads, a new thread is started (or reused). Otherwise <em>slot</em> stays in the queue until a thread in this pool finishes its previous task and processes <em>slot.</em> <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>slot</em> </td><td>A new task for the thread pool. </td></tr> </table> </dl> <dl compact><dt><b>Exceptions:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>Glib::ThreadError</em> </td><td>An error can only occur when a new thread couldn't be created. In that case <em>slot</em> is simply appended to the queue of work to do. </td></tr> </table> </dl> </td> </tr> </table> <a name="a3" doxytag="Glib::ThreadPool::set_max_threads"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void Glib::ThreadPool::set_max_threads </td> <td class="md" valign="top">(</td> <td class="md" nowrap valign="top">int </td> <td class="mdname1" valign="top" nowrap> <em>max_threads</em> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Sets the maximal allowed number of threads for the pool. <p> A value of -1 means that the maximal number of threads is unlimited. Setting <em>max_threads</em> to 0 means stopping all work for pool. It is effectively frozen until <em>max_threads</em> is set to a non-zero value again. <p> A thread is never terminated while it is still running. Instead the maximal number of threads only has effect for the allocation of new threads in <a class="el" href="classGlib_1_1ThreadPool.html#a2">ThreadPool::push()</a>. A new thread is allocated whenever the number of currently running threads in the pool is smaller than the maximal number. <p> <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>max_threads</em> </td><td>A new maximal number of threads for the pool. </td></tr> </table> </dl> <dl compact><dt><b>Exceptions:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>Glib::ThreadError</em> </td><td>An error can only occur when a new thread couldn't be created. </td></tr> </table> </dl> </td> </tr> </table> <a name="d0" doxytag="Glib::ThreadPool::set_max_unused_threads"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void Glib::ThreadPool::set_max_unused_threads </td> <td class="md" valign="top">(</td> <td class="md" nowrap valign="top">int </td> <td class="mdname1" valign="top" nowrap> <em>max_threads</em> </td> <td class="md" valign="top">) </td> <td class="md" nowrap><code> [static]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Sets the maximal number of unused threads to <em>max_threads.</em> <p> If <em>max_threads</em> is -1, no limit is imposed on the number of unused threads. <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>max_threads</em> </td><td>Maximal number of unused threads. </td></tr> </table> </dl> </td> </tr> </table> <a name="a8" doxytag="Glib::ThreadPool::shutdown"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void Glib::ThreadPool::shutdown </td> <td class="md" valign="top">(</td> <td class="md" nowrap valign="top">bool </td> <td class="mdname1" valign="top" nowrap> <em>immediately</em> = false </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Frees all resources allocated for the pool. <p> If <em>immediately</em> is <code>true</code>, no new task is processed. Otherwise the pool is not freed before the last task is processed. Note however, that no thread of this pool is interrupted while processing a task. Instead at least all still running threads can finish their tasks before the pool is freed. <p> This method does not return before all tasks to be processed (dependent on <em>immediately,</em> whether all or only the currently running) are ready. After calling <a class="el" href="classGlib_1_1ThreadPool.html#a8">shutdown()</a> the pool must not be used anymore. <p> <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign=top><em>immediately</em> </td><td>Should the pool shut down immediately? </td></tr> </table> </dl> </td> </tr> </table> <a name="d3" doxytag="Glib::ThreadPool::stop_unused_threads"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void Glib::ThreadPool::stop_unused_threads </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap><code> [static]</code></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Stops all currently unused threads. <p> This does not change the maximal number of unused threads. This function can be used to regularly stop all unused threads e.g. from <a class="el" href="group__MainLoop.html#a7">Glib::signal_timeout()</a>. </td> </tr> </table> <a name="a6" doxytag="Glib::ThreadPool::unprocessed"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> unsigned int Glib::ThreadPool::unprocessed </td> <td class="md" valign="top">(</td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap> const</td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Returns the number of tasks still unprocessed in the pool. <p> <dl compact><dt><b>Returns:</b></dt><dd>The number of unprocessed tasks. </dd></dl> </td> </tr> </table> <hr>The documentation for this class was generated from the following file:<ul> <li><a class="el" href="threadpool_8h.html">threadpool.h</a></ul> <hr><address><small> Generated for gtkmm by <a href="http://www.doxygen.org/index.html"> Doxygen</a> 1.3-rc1 © 1997-2001</small></address> </body> </html>