By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,799 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,799 IT Pros & Developers. It's quick & easy.

developing network simulation.

P: n/a
1. In a network, there are a number of nodes. Each node has a queue and a
thread, performing the discrete event simulation.
class CNode
{...
queue q;
CWinThread* pthread;

void Start();//to execute the thread
....
}; where CWinThread is the thread class in MFC.
In the main program,
void main()
{
CNode node[10];
for (i=0;i<10;i++)
node[i].Start();
.....
}

2. but, I can not find a way to transmit the events between the nodes. For
example, in the thread of node[0], triggered by an action, it will send a
message MSG to node[1] and insert this event to node[1]'s queue. It seems
impossible to achieve this based on this design.

Can you please give some comments on this problem, the class design and the
program architecuter as well as the design pattern? Any comments are greatly
appreaciated.

--
Yan ZHANG
http://www.nict.com.sg/zhang/
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Yan ZHANG wrote:
1. In a network, there are a number of nodes. Each node has a queue and a
thread, performing the discrete event simulation.
class CNode
{...
queue q;
CWinThread* pthread;

void Start();//to execute the thread
...
}; where CWinThread is the thread class in MFC.
In the main program,
void main()
{
CNode node[10];
for (i=0;i<10;i++)
node[i].Start();
....
}

2. but, I can not find a way to transmit the events between the nodes. For
example, in the thread of node[0], triggered by an action, it will send a
message MSG to node[1] and insert this event to node[1]'s queue. It seems
impossible to achieve this based on this design.

Can you please give some comments on this problem, the class design and
the program architecuter as well as the design pattern? Any comments are
greatly appreaciated.

--
Yan ZHANG
http://www.nict.com.sg/zhang/


I have developed an Artificial Chemistry simulator. At the heart of the
simulator is a network of nodes and links between the nodes. In the
Reactor, each node corresponds to a Realised_Molecute_Type. The system
maintains a list of Realisable_Interaction_Types. The main simulation works
on this list of Realisable_Interaction_Types, creating and removing
Realised_Molecute_Type. I make a lot of use of STL lists, eg to maintain a
list of Realisable_Interaction_Types associated with a particular
Realised_Molecute_Type.

The UML diagrams for the Chemistry and Reactor subsystems are at

http://graffiti.virgin.net/c.gordon-...SimSoup/Design
Chemistry_Subsystem.html

The code is open source and can also be downloaded fom the same site.

--
Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Jul 22 '05 #2

P: n/a
All node threads in your program would be blocked, waiting for an
event.
A "check mailbox" event can be raised when a thread adds a message
to the queue of another thread.

When the receiving thread gets the "check mailbox" event, it checks the
message queue.

Deepa
--
http://www.EventHelix.com/EventStudio
EventStudio 2.5 - Automate Sequence Diagram Generation

Jul 22 '05 #3

P: n/a
Responding to ZHANG...
1. In a network, there are a number of nodes. Each node has a queue and a
thread, performing the discrete event simulation.
class CNode
{...
queue q;
CWinThread* pthread;

void Start();//to execute the thread
...
}; where CWinThread is the thread class in MFC.
In the main program,
void main()
{
CNode node[10];
for (i=0;i<10;i++)
node[i].Start();
....
}

2. but, I can not find a way to transmit the events between the nodes. For
example, in the thread of node[0], triggered by an action, it will send a
message MSG to node[1] and insert this event to node[1]'s queue. It seems
impossible to achieve this based on this design.


Separate out the queue as a standalone object associated with CNode so
that it is accessible directly.

1 triggers 1
[Queue] ----------------- [Node]
| * | *
| pushes events on |
| |
+-----------------------+
|
[Network]

[Network] keeps track of what Queues a particular Node can talk to.

Use a semaphore to determine whether the thread is paused. When an
event is pushed, queue the event and then check if the thread is paused.
If so, invoke pop(). Pop() sets the semaphore, starts the thread, and
invokes the Node method (e.g., Start) for the next event in the queue.
When Node is finished its synchronous processing (i.e., control is
returned to pop()), check the queue for additional events and continue
to pop them. When the queue is empty, pause the thread and unset the
semaphore. During its processing Node places the events on the relevant
Queues using push().

Now anyone (e.g., any CNode) can push an event asynchronously with the
thread because push() isn't in the execution thread. The semaphore
ensures that only one event at a time is processed. Now you can also
eliminate the loop in main(); all you need is for main() to provide a
single "seed" event and the nodes will talk to one another.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hs*@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog (under constr): http://pathfinderpeople.blogs.com/hslahman
(888)-OOA-PATH

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.