Thread 2-LabVIEW Execution System in LabVIEW program [write efficient code]

Source: Internet
Author: User
Thread 2 in LabVIEW Program-Execution System of LabVIEW 2. Execution System of LabVIEW 1. What is execution system?     In the early days, LabVIEW's VI was run in a single thread, and multithreading was introduced only after LabVIEW 5.0. In fact, for LabVIEW function modules placed side by side, even if LabVIEW does not allocate different threads to them, it is usually "Parallel Execution. LabVIEW will split them into fragments and execute them in turn: This is like LabVIEW designed a multi-thread scheduling system for itself to execute multiple tasks in a single thread of the system in parallel.
      In LabVIEW, a mechanism for scheduling and running VI code is called an execution system. The current labivew has six execution systems: user Interface execution system, standard execution system, instrument I/O execution system, data collection execution system, and other 1 and other 2 systems. Many Sub-VI used in an application can be run in different execution systems. You can select the execution page on the VI properties panel. on this page, you can specify or change the preferred execution system for a VI.2. Relationship between execution system and thread     LabVIEW
After multithreading is supported, the code in different execution systems must run in different threads. The User Interface execution system has only one thread and is the main thread of the program. This is different from other execution systems. Other execution systems can open up multiple threads to execute code. In addition to setting the VI Execution System, you can also set its priority. The priority is divided into five levels (subroutine is not considered for the moment ). Before LabVIEW 7.0, LabVIEW enables an independent thread for the priority of each stage in the same execution system by default.
After 7.0, LabVIEW will enable four threads for the priority of each stage in each Execution System by default. Of course, you can use \ VI. Lib \ utility \ sysinfo. LLB \ threadconfig. VI to change this setting. But it is better for common users not to change it.
      When writing multi-threaded programs in C language, you must note that too many threads cannot be opened, because thread development, destruction, and switching are also expensive. Too many threads may cause worse efficiency. However
LabVIEW is much more convenient. With the default settings, LabVIEW can open up to five threads for your program: one user interface thread and four threads with the Standard execution system priority. Five threads won't cause obvious efficiency loss.3. User Interface Execution System     All interface-related code in the program is executed in the user interface execution system. Even if you have set up another execution system for a VI, after the front panel of the VI is opened, the data update operations on the VI will be run under the execution system on the user interface. There are also some work, such as using the open VI reference node to dynamically load a VI to the memory, it also runs under the user interface execution system.
      As mentioned above, the user interface execution system is the most special execution system, because it has only one thread (we can name this thread as the user interface thread ). When LabVIEW is started, this thread is created, and the threads in other execution systems are created by LabVIEW only when they are used.      In the example in Figure 1, if it is running in another thread, it will fill up my dual-core CPU. For more information, see Chapter 1 (LabVIEW
Is an automatic multi-threaded language. However, if we change the VI Execution System to the user interface execution system, the two loops will run in the same thread, and one of my dual-core CPUs will occupy 100% of the cores, the other is basically idle.      Figure 2 shows a picture of the VI running process. Although the program runs in a single line, the two loops are still running in parallel, and the data of the two display controls will increase alternately.

    
Figure 1 and 2: parallel Tasks running under the interface thread-single thread

      Because LabVIEW is automatic and multithreading, if some modules cannot guarantee the security of multithreading, they need to be set to run in the user interface thread. This is equivalent to forcing them to execute in the same thread to ensure security. The specific example is discussed in the next section.4. Several other execution systems     There are several other optional items in the execution system column.
      "Same as caller" is the default option, indicating that the VI follows the execution system set by the upper-level vi that calls it. If "Same as caller" is selected for the top-level VI, the Standard execution system is selected.
      The Standard execution system is the most common configuration method.
      The instrument I/O execution system is generally used to send commands to or read data from an external instrument. This is an important operation in the program and needs to be run in time. Therefore, the priority of threads in the I/O execution system is higher than that in other execution systems.
      "Data Acquisition" Data Collection execution system is generally used for fast data collection. The data stack area of threads in the data collection execution system is relatively large.
      "Other 1", "other 2", other 1, and other 2 execution systems have nothing special. If you must run some VI in a separate thread, you can use these two options.
      In most cases, the user interface Execution System and Standard execution system are enough.

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.