glibmm 2.80.0
Public Member Functions | List of all members
Glib::Dispatcher Class Reference

Signal class for inter-thread communication. More...

#include <glibmm/dispatcher.h>

Public Member Functions

 Dispatcher ()
 Create new Dispatcher instance using the default main context.
 
 Dispatcher (const Dispatcher &)=delete
 
Dispatcheroperator= (const Dispatcher &)=delete
 
 Dispatcher (const Glib::RefPtr< MainContext > &context)
 Create new Dispatcher instance using an arbitrary main context.
 
 ~Dispatcher () noexcept
 
void emit ()
 Same as the const version.
 
void operator() ()
 Same as the const version.
 
void emit () const
 
void operator() () const
 
sigc::connection connect (const sigc::slot< void()> &slot)
 
sigc::connection connect (sigc::slot< void()> &&slot)
 

Detailed Description

Signal class for inter-thread communication.

Glib::Dispatcher 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.

No mutex locking is involved, apart from the operating system's internal I/O locking. That implies some usage rules:

Notes about performance:

Using Glib::Dispatcher on Windows:

Glib::Dispatcher 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.

Examples
thread/dispatcher.cc.

Constructor & Destructor Documentation

◆ Dispatcher() [1/3]

Glib::Dispatcher::Dispatcher ( )

Create new Dispatcher instance using the default main context.

Exceptions
Glib::FileError

◆ Dispatcher() [2/3]

Glib::Dispatcher::Dispatcher ( const Dispatcher )
delete

◆ Dispatcher() [3/3]

Glib::Dispatcher::Dispatcher ( const Glib::RefPtr< MainContext > &  context)
explicit

Create new Dispatcher instance using an arbitrary main context.

Exceptions
Glib::FileError

◆ ~Dispatcher()

Glib::Dispatcher::~Dispatcher ( )
noexcept

Member Function Documentation

◆ connect() [1/2]

sigc::connection Glib::Dispatcher::connect ( const sigc::slot< void()> &  slot)

◆ connect() [2/2]

sigc::connection Glib::Dispatcher::connect ( sigc::slot< void()> &&  slot)

◆ emit() [1/2]

void Glib::Dispatcher::emit ( )

Same as the const version.

Deprecated:
2.76: Use the const version instead.

◆ emit() [2/2]

void Glib::Dispatcher::emit ( ) const

◆ operator()() [1/2]

void Glib::Dispatcher::operator() ( )

Same as the const version.

Deprecated:
2.76: Use the const version instead.

◆ operator()() [2/2]

void Glib::Dispatcher::operator() ( ) const

◆ operator=()

Dispatcher & Glib::Dispatcher::operator= ( const Dispatcher )
delete