Post / Sign and Smart Index

I would like to implement a simple publish / publish template where:

One publisher publishes a token (pointer to an object) to its subscribers. Publisher and subscribers are all independent streams. I plan to add a thread-safe queue to each subscriber so that the publisher can continue to distribute tokens to subscribers while they process the tokens.

As you can see, this means that all subscribers actually use the same pointers (note: subscribers cannot change a pointed object in any case, so there are no problems). As soon as the shared index will no longer be used by any of the subscribers, it would be very nice if the index could automatically delete itself as soon as the last thread of the subscriber is executed with it.

Is this a good place to use smart pointer? If so, which of the smart pointers should I use?

I am developing Windows using MSVC2008 and using Intel TBB, Boost and Qt.

+3
source share
2 answers

If I assume your design is viable (it smells like a funny null context, but it may well be correct), boost :: shared_ptr might be the way to go.

http://www.boost.org/doc/libs/1_38_0/libs/smart_ptr/smart_ptr.htm

Edit: switch to :: shared_ptr from :: weak_ptr because I'm an idiot ...

+4
source

, , - COM . , - boost::shared_ptr, boost::intrusive_ptr ATL CComPtr. shared_ptr, ref.

+4

Source: https://habr.com/ru/post/1703405/


All Articles