Thread 3 in LabVIEW Program-thread priority [writing efficient code]

Source: Internet
Author: User
Thread 3 in LabVIEW Program-thread priority 3. thread priority

    In the VI property settings Panel VI properties-> execution, there is also a drop-down control used to set the thread priority (priority ). This option can change the priority of the VI running thread.

   There are six priority settings, the first five of which are the five priorities from low to high. The higher the priority, the easier it is to seize CPU resources. For example, if you set the priority of a VI responsible for computing to the time critical priority, the CPU will allocate time segments to the thread where the VI is located more frequently during program running, the cost is that the computing time allocated to other threads is reduced. If this program has another thread responsible for interface refresh, the user will find that after the priority of the execution thread is increased, the interface refresh will become dull, or even no response at all.

   The last item of priority setting is subroutine, which is very different from the first five. Strictly speaking, subroutine cannot be set as a priority.Will change
VI attributes:
   Information on the front panel of the VI set to subroutine will be removed. Therefore, such a VI cannot be used as an interface or executed independently.
   Debugging information of the VI set to subroutine will also be removed. Such a VI cannot be debugged.
   When the program runs to the VI set to subroutine, the program will temporarily become a single-thread execution mode. That is, the program will not be interrupted by other threads until subroutine VI is executed.
   The above three guarantees subroutineVI The most CPU resources can be obtained during execution. Some vi that are used as key operations are not particularly time-consuming and can be set
Subroutine to improve the running speed. For example, if there is a VI, its input is a numerical array, and the output is the average value of the data set. This operation needs to be completed in the program as soon as possible to avoid delay in data display. This VI is a very suitable subroutine.VI.

   Note the following when setting the VI priority.
   Generally, increasing the priority of a VI generally does not significantly shorten the running time of the program. It increases the priority and requires a lot of CPU time, but the CPU usage frequency increases.
   High-priority VI may not be executed before low-priority VI. Currently, the commonly used multi-threaded operating systems are preemptible, with a high thread priority. The possibility of grabbing the CPU is higher than that of the low-level thread, but it is not absolute.
   Use subroutinePay special attention to this because it will change your program into single-threaded execution, which in many cases will reduce the efficiency of your program. For example, a VI is not just used for calculation. It also needs to wait for data from other devices so that the VI cannot be set to subroutine. Nowadays, multi-core CPUs are very popular. On such computers, programs running in a single thread are generally less efficient than multithreading, which also needs to be considered.

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.