multithread deisign for large and fast data exchange‏


Forum Post 0 Answers multithread deisign for large and fast data exchange‏

Hi,
I am doing C++ multithreaded coding on Linux.

Each thread hold some messagers, who need to talk (exchange message) to other messagers.

Each messager is not only a message pruducer but also a message consumer.

If a messager needs to talk to another messager and both of them are held by the same thread , that is intra-hread talk.

Otherwise, it is inter-thread talk.

A messager can generate multiple messages, each of which has a distinct message-receiver ID. Each messager needs to do some computing tasks in order to produce a message.

Only the messager with match ID can receive and consume the message.

All messagers work asynchronously and the message exchange (like a multicast) pairs are fixed and do not change in the whole process of the program.

In order to simulate the above message exchange, I want to associate a priority message queue with each thread such that

(1) Each messager in a priority queue is an element. Whenever a messager's computing task is done and its message is ready for sending out, it has the highest priority and it is poped out and saved in a map with the messager's receiver ID as key.

(2) Then, the messager is push backed to the queue again and wait for receiving messgae from its talk pairs and do the above step (1).

(3) each thread is associated with a queue like this. Sometimes, do inter-thread talk and some times do intra-thread talk.


My questions:

How to efficiently implement the above idea with STL/boost data containers, thread, thread pool, STL/boost algorithm or other boost components ?

Are there other better ways to simulate the talk ?

Any help, advice or idea is really appreciated.


Thanks

- jinxuding October 10, 2011 | Flag |






Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More