I am implementing a message passing algorithm. Messages are transmitted between neighboring nodes when they have enough information on a node to compose a message - information that is transmitted by a node from neighboring nodes. The implementation is trivial if I make each of the messages a stream and use boost :: condition to put the stream to sleep until the required information is available.
Unfortunately - I have 100k nodes in the graph, which would mean 300k threads. When I asked how to make so many threads, the answer was such that I shouldn't - and reverse engineer instead.
My question is: is there a standard design pattern for expecting a condition? Perhaps some kind of asynchronous control pattern?
EDIT: I think I can do this with a proactor template. I edited the tags to enable boost :: asio - to find out if anyone has any suggestions with this.
So, the discussion can be specific, here is how the messages are defined so far:
class Message { public: Message(const Node* from, Node* to) : m_from(from), m_to(to) {} void operator()() { m_to->ReceiveMessage( m_from->ComposeMessage() ); } private: Node *m_from, *m_to; };
These message functions are currently running with boost :: thread. Then we have
class Node { Node(Node* Neighbour1, Node* Neighbour2, Node* Neighbour3);
I like the transparency of the code and, if possible, I would like to support the same interfaces, having some alternative to conditional locking?
source share