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