<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>glibmm: Glib::Dispatcher Class Reference</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li class="current"><a href="annotated.html"><span>Classes</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> <div class="tabs2"> <ul class="tablist"> <li><a href="annotated.html"><span>Class List</span></a></li> <li><a href="classes.html"><span>Class Index</span></a></li> <li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li> <li><a href="functions.html"><span>Class Members</span></a></li> </ul> </div> <div class="navpath"> <ul> <li><a class="el" href="namespaceGlib.html">Glib</a> </li> <li><a class="el" href="classGlib_1_1Dispatcher.html">Dispatcher</a> </li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#pub-methods">Public Member Functions</a> </div> <div class="headertitle"> <h1>Glib::Dispatcher Class Reference<br/> <small> [<a class="el" href="group__Threads.html">Threads</a>]</small> </h1> </div> </div> <div class="contents"> <!-- doxytag: class="Glib::Dispatcher" --> <p>Signal class for inter-thread communication. <a href="#_details">More...</a></p> <p><code>#include <glibmm/dispatcher.h></code></p> <p><a href="classGlib_1_1Dispatcher-members.html">List of all members.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="pub-methods"></a> Public Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Dispatcher.html#a1883255c63f36e1d218ccf3f1abfa992">Dispatcher</a> ()</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Create new <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> instance using the default main context. <a href="#a1883255c63f36e1d218ccf3f1abfa992"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Dispatcher.html#a14692fe3e39140fc164cbd03149a7ce1">Dispatcher</a> (const <a class="el" href="classGlib_1_1RefPtr.html">Glib::RefPtr</a>< <a class="el" href="classGlib_1_1MainContext.html">MainContext</a> >& context)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Create new <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> instance using an arbitrary main context. <a href="#a14692fe3e39140fc164cbd03149a7ce1"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Dispatcher.html#a6d220afa9063f8cf1364d5a1c73eb010">~Dispatcher</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Dispatcher.html#a07b89c90f931db118c8c184d0615ce92">emit</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Dispatcher.html#a4610275deedf1324bf71afde1c8c71ea">operator()</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="elRef" href="../../../libsigc++-2.0/reference/html/structsigc_1_1connection.html">sigc::connection</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Dispatcher.html#a63645395ac79c03b5ec9e81d8099dea7">connect</a> (const <a class="elRef" href="../../../libsigc++-2.0/reference/html/classsigc_1_1slot.html">sigc::slot</a>< void >& slot)</td></tr> </table> <hr/><a name="_details"></a><h2>Detailed Description</h2> <p>Signal class for inter-thread communication. </p> <p><a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Glib::Dispatcher</a> works similar to sigc::signal<void>. But unlike normal signals, the notification happens asynchronously through a pipe. This is a simple and efficient way of communicating between threads, and especially useful in a thread model with a single GUI thread.</p> <p>No mutex locking is involved, apart from the operating system's internal I/O locking. That implies some usage rules:</p> <ul> <li>Only one thread may connect to the signal and receive notification, but multiple senders are allowed even without locking. </li> <li>The GLib main loop must run in the receiving thread (this will be the GUI thread usually). </li> <li>The <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> object must be instantiated by the receiver thread. </li> <li>The <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> object should be instantiated before creating any of the sender threads, if you want to avoid extra locking.</li> </ul> <p>Notes about performance:</p> <ul> <li>After instantiation, <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Glib::Dispatcher</a> will never lock any mutexes on its own. The interaction with the GLib main loop might involve locking on the <em>receiver</em> side. The <em>sender</em> side, however, is guaranteed not to lock, except for internal locking in the <code>write()</code> system call. </li> <li>All <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> instances of a receiver thread share the same pipe. That is, if you use <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Glib::Dispatcher</a> only to notify the GUI thread, only one pipe is created no matter how many <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> objects you have.</li> </ul> <p>Using <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Glib::Dispatcher</a> on Windows:</p> <p><a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Glib::Dispatcher</a> also works on win32-based systems. Unfortunately though, the implementation cannot use a pipe on win32 and therefore does have to lock a mutex on emission, too. However, the impact on performance is likely minor and the notification still happens asynchronously. Apart from the additional lock the behavior matches the Unix implementation. </p> <dl><dt><b>Examples: </b></dt><dd> <p><a class="el" href="thread_2dispatcher_8cc-example.html#_a3">thread/dispatcher.cc</a>.</p> </dd> </dl><hr/><h2>Constructor & Destructor Documentation</h2> <a class="anchor" id="a1883255c63f36e1d218ccf3f1abfa992"></a><!-- doxytag: member="Glib::Dispatcher::Dispatcher" ref="a1883255c63f36e1d218ccf3f1abfa992" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">Glib::Dispatcher::Dispatcher </td> <td>(</td> <td class="paramname"> )</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Create new <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> instance using the default main context. </p> <dl><dt><b>Exceptions:</b></dt><dd> <table class="exception"> <tr><td class="paramname"><a class="el" href="classGlib_1_1FileError.html" title="Exception class for file-related errors.">Glib::FileError</a></td><td></td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="a14692fe3e39140fc164cbd03149a7ce1"></a><!-- doxytag: member="Glib::Dispatcher::Dispatcher" ref="a14692fe3e39140fc164cbd03149a7ce1" args="(const Glib::RefPtr< MainContext > &context)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">Glib::Dispatcher::Dispatcher </td> <td>(</td> <td class="paramtype">const <a class="el" href="classGlib_1_1RefPtr.html">Glib::RefPtr</a>< <a class="el" href="classGlib_1_1MainContext.html">MainContext</a> >& </td> <td class="paramname"> <em>context</em> )</td> <td><code> [explicit]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Create new <a class="el" href="classGlib_1_1Dispatcher.html" title="Signal class for inter-thread communication.">Dispatcher</a> instance using an arbitrary main context. </p> <dl><dt><b>Exceptions:</b></dt><dd> <table class="exception"> <tr><td class="paramname"><a class="el" href="classGlib_1_1FileError.html" title="Exception class for file-related errors.">Glib::FileError</a></td><td></td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="a6d220afa9063f8cf1364d5a1c73eb010"></a><!-- doxytag: member="Glib::Dispatcher::~Dispatcher" ref="a6d220afa9063f8cf1364d5a1c73eb010" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">Glib::Dispatcher::~Dispatcher </td> <td>(</td> <td class="paramname"> )</td> <td></td> </tr> </table> </div> <div class="memdoc"> </div> </div> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="a63645395ac79c03b5ec9e81d8099dea7"></a><!-- doxytag: member="Glib::Dispatcher::connect" ref="a63645395ac79c03b5ec9e81d8099dea7" args="(const sigc::slot< void > &slot)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="elRef" href="../../../libsigc++-2.0/reference/html/structsigc_1_1connection.html">sigc::connection</a> Glib::Dispatcher::connect </td> <td>(</td> <td class="paramtype">const <a class="elRef" href="../../../libsigc++-2.0/reference/html/classsigc_1_1slot.html">sigc::slot</a>< void > & </td> <td class="paramname"> <em>slot</em> )</td> <td></td> </tr> </table> </div> <div class="memdoc"> </div> </div> <a class="anchor" id="a07b89c90f931db118c8c184d0615ce92"></a><!-- doxytag: member="Glib::Dispatcher::emit" ref="a07b89c90f931db118c8c184d0615ce92" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void Glib::Dispatcher::emit </td> <td>(</td> <td class="paramname"> )</td> <td></td> </tr> </table> </div> <div class="memdoc"> </div> </div> <a class="anchor" id="a4610275deedf1324bf71afde1c8c71ea"></a><!-- doxytag: member="Glib::Dispatcher::operator()" ref="a4610275deedf1324bf71afde1c8c71ea" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void Glib::Dispatcher::operator() </td> <td>(</td> <td class="paramname"> )</td> <td></td> </tr> </table> </div> <div class="memdoc"> </div> </div> </div> <hr class="footer"/><address class="footer"><small>Generated on Tue Apr 5 2011 16:07:14 for glibmm by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address> </body> </html>