This module is not included in the entire platform framework, but in the form of tools to be put aside. However, the addition of the module can greatly improve the visualization of the simulation experiment. (right when is familiar with multithreading, haha!) )
The simulation platform wants to implement multi-threaded operation and single step, and want the structure as simple as possible. It is necessary to note that a single step is not just using thread.stop () to break a thread, but rather nonviolent to stop it when a step is finished.
As shown, Mutithreadhelper needs to load data, including environment configuration data (config), experimental data (Hashtable), and so on, and then there are three functions:
--start used to start the start thread
--step for Single Step
--stop is used to stop the thread, as opposed to start, notice the non-violent stop!
Here I have been talking about nonviolent cessation, and the approximate structure should be this:
intbstop;//0 means thread ends, 1 means thread continues, 2 means thread hangsvoidstart () {bstop=1; Thread.Start ();}voidStep () {bstop=2; if(thread.state==Suspend) {Thread.Resume (); } Else if(thread.state!=Run) {Thread.Start (); }}voidStop () {bstop=0;}voiddoWork () {//Do something if(Bstop = =0) {thread.stop (); } Else if(Bstop = =2) {thread.suspend (); }}
Note that the above is pseudo-code and does not belong to any language. The general idea is to manage the running of a thread function through a variable, and when the thread does not perform a step, it checks the variable and makes the corresponding change.
Sensor simulation Platform-multi-threading and Out (vi)