Sensor simulation Platform-multi-threading and Out (vi)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.