Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Class shared_connection_block

boost::signals2::shared_connection_block — Blocks a connection between a signal and a slot.


// In header: <boost/signals2/shared_connection_block.hpp>

class shared_connection_block {
  // construct/copy/destruct
  shared_connection_block(const boost::signals2::connection & = connection(), 
                          bool = true);
  shared_connection_block(const boost::signals2::shared_connection_block &);
  operator=(const boost::signals2::shared_connection_block &);

  // connection blocking
  void unblock();
  void block();
  bool blocking() const;

  // miscellaneous methods
  boost::signals2::connection connection() const;


A shared_connection_block object blocks a connection, preventing the associated slot from executing when the associated signal is invoked. The connection will remain blocked until every shared_connection_block that references the connection releases its block. A shared_connection_block releases its block when it is destroyed or its unblock method is called.

A shared_connection_block is safe to use even after the signals2::connection object it was constructed from has been destroyed, or the connection it references has been disconnected.

Note, blocking a connection does not guarantee the associated slot has finished execution if it is already in the process of being run when the connection block goes into effect. This is similar to the behaviour of disconnect, in that blocking a connection will not wait for the connection's associated slot to complete execution. This situation may arise in a multi-threaded environment if the connection block goes into effect concurrently with signal invocation, or in a single-threaded environment if a slot blocks its own connection.

shared_connection_block public construct/copy/destruct

  1. shared_connection_block(const boost::signals2::connection & conn = connection(), 
                            bool initially_blocking = true);


    Creates a shared_connection_block which can block the connection referenced by conn. The shared_connection_block will initially block the connection if and only if the initially_blocking parameter is true. The block on the connection may be released by calling the unblock method, or destroying the shared_connection_block object.

    Default construction of a shared_connection_block results in a shared_connection_block which references the NULL connection. Such a shared_connection_block is safe to use, though not particularly useful until it is assigned another shared_connection_block which references a real connection.


    this->blocking() == initially_blocking

  2. shared_connection_block(const boost::signals2::shared_connection_block & other);


    Copy constructs a shared_connection_block which references the same connection as other.


    this->connection() == other.connection()

    this->blocking() == other.blocking()

  3. shared_connection_block& 
    operator=(const boost::signals2::shared_connection_block & rhs);


    Makes this reference the same connection as rhs.


    this->connection() == rhs.connection()

    this->blocking() == rhs.blocking()


    Will not throw.

  4. ~shared_connection_block();


    If blocking() is true, releases the connection block.

shared_connection_block connection blocking

  1. void unblock();


    If blocking() is true, releases the connection block. Note, the connection may remain blocked due to other shared_connection_block objects.


    this->blocking() == false.

  2. void block();


    If blocking() is false, reasserts a block on the connection.


    this->blocking() == true.

  3. bool blocking() const;


    true if this is asserting a block on the connection.


    this->blocking() == true implies connection::blocked() == true for the connection. However, this->blocking() == false does not necessarily imply connection::blocked() == false, since the connection may be blocked by another shared_connection_block object.

shared_connection_block miscellaneous methods

  1. boost::signals2::connection connection() const;


    A connection object for the connection referenced by this.