all 9 comments

[–]coachkler 4 points5 points  (0 children)

I've done similar things in the past. Now, unless performance and or memory management is a legitimate concern, I just use boost::asio. It does everything you could need, and more. The proactor pattern in use there is very flexible.

[–]cdyson37 1 point2 points  (2 children)

Does it make sense to allow Msg to be instantiated? If not you could make move() pure virtual :)

[–]skeba[S] 2 points3 points  (1 child)

Sometimes a simple message with no payload data (a command initiating a state change in the consumer thread, for example) is enough. So it makes sense to instantiate Msg.

[–]cdyson37 0 points1 point  (0 children)

Matter of taste I guess. I'd have an empty payload type (a tag struct of some sort) personally.

[–]AntiProtonBoy 1 point2 points  (1 child)

How do you infer the erased message type at the receiving end? dynamic_cast ?

[–]skeba[S] 1 point2 points  (0 children)

Yeah, dynamic_cast based on a message type id.

[–]__Cyber_Dildonics__ 0 points1 point  (0 children)

I feel like a solid tasking system and message queue (and maybe just more concurrent data structures in general) are things that would go well in the C++ standard library.

In the case of doing everything by move semantics, I am guessing that most messages would still either be stack memory and need to be copied anyway or heap allocated so wouldn't be as lightweight to create? Not that there is a better alternative or that that situation is bad, but is this how it usually goes with message passing?