Cinder Signals vs std::signals - best way to implement the Observer Pattern

Hey guys,

I’m currently assessing the ways to build a clean observer pattern system. Of course when googling the first thing that comes up is std’s signal and slots (C++11 which is absolutely fine). I saw that Cinder also has an implementation of Signals in Signals.h and uses that under the hood.
How does Cinder’s signal class compares to std’s ? or are they targeted at different goals and just have the same name? Before diving into this I wanted to ask around in the forums to see if anybody has gone down this road before and get some tips :slight_smile:

Thanks a bunch

Cinder’s signal class is based on a version of Tim Janik’s SimpleSignal library. For a comparison and motivation, see this article. Note that his library is roughly 4 years old and things may have changed since. The std::signals library did not exist yet (edit: turns out it doesn’t exist at all, see comments below) and I’m not sure if it is based on boost::signals2 or not. You may want to do some profiling yourself.

However, know that Cinder’s class has been researched and well thought out and offers great performance and flexibility. The only drawback I can think of is that you can’t control the order in which a signal is processed (you can’t sort the listeners). You can assign a priority, but it is not efficient to have a unique priority for each listener.

-Paul

Edit: I should add that Cinder’s signals are not thread safe. If you’re planning on using multiple threads, you might want to use std::signals instead.

Cheers for the reply Paul. I just checked the article and it was quite an interesting read. Also thanks for the info about Cinder’s signal implementation. Actually I’d like my implementation to support multithreading if possible and as you said std::signals seem to fit my purpose best.

when did the standard library get a signals implementation? I can’t seem to find anything written about it anywhere.

That’s true, my bad. I was more referring to signal implementations using the new C++11 standard features, something along these line: 1, 2, 3 and 4. Judging by Paul’s reply and the link he mentioned I think he meant the same thing (the article talks about a SimpleSignal class which is a C++11 implementation).
Sorry if the title and discussion was misleading guys! Peace :slight_smile:

Haha, actually I just assumed there was a std::signals library, because Kino mentioned it.

1 Like