I would like to implement a simple Publish/Subscribe pattern where:
A single publisher publishes a token (a pointer to an object) to its subscribers. Publisher and subscribers are all independent threads. I plan to add thread-safe queue to each of the subscriber such that Publisher can keep distributing the tokens to the subscribers while they are processing the tokens.
As you can see, that means all of the subscribers actually share the same pointers (note: subscribers cannot modify the pointed object in anyway, so no problem there). Once the shared pointer is not used by any of the subscribers anymore, it would be really nice if the pointer could auto-delete itself once the last subscriber thread is done with it.
Is this a good place to use a smart pointer? If so, which ones of the smart pointers should I use?
I develop on Windows with MSVC2008, and am using Intel TBB, Boost and Qt.