Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are boost::signals slots called synchronously or asynchronously?

Can anyone tell me are boost::signals slots called synchronously or asynchronously?

For example I have this piece of code:

struct Hello
{
  void operator()() const
  {
    std::cout << "Hello ";
  }
};

struct World
{
  void operator()() const
  {
    std::cout << " world!" << std::endl;
  }
};

boost::signal<void ()> sig;

sig.connect(Hello());
sig.connect(World());

sig();

cout << "Foo";

How does the execution thread work? Does the execution wait for Hello() and World() to execute and just after that "Foo" is printed or does it call them asynchronously(printing "Foo" and calling Hello() and World() execute in an undefined order)?

like image 291
Jacob Krieg Avatar asked Feb 08 '13 12:02

Jacob Krieg


1 Answers

In Boost.Signals slots are called synchronously and slots connected to the same signal are called in the order in which they were added. This is true also of the thread-safe variant, Boost.Signals2

like image 140
Nicola Musatti Avatar answered Sep 27 '22 22:09

Nicola Musatti