VS C + + concurrent programming

Source: Internet
Author: User

1.vs2012 and above, supports concurrent programming of the C++11 thread class.

Related Materials can refer to the blog: http://www.cnblogs.com/rangozhang/p/4468754.html

2. However, for the previous version, you can implement the class member function to create a child thread implementation concurrency in the following manner.

The first need to implement the thread class of the run function, it defines the thread class header file and its corresponding function implementation, concrete 1, 2 is as follows:

Figure 1 Header file for thread class

Figure 2 Implementation file for the thread class

Notice that the inherited Derivedthread class simply writes the concurrently executed function within its corresponding run () function.

It is important to note that the conditions for the end of the child thread run. The following is an example of a project to further illustrate its importance.

In the above, the class member tempgrayimg is a known input image, Tempoptmmstir is an unknown target mask image, the previous error is: The target mask image Tempoptmmstir whether the number of non-0 pixels is zero as the current child thread is the end of the flag, However, the problem is that if the current thread executes part of the target, the Tempoptmmstir mask image has a number of non-0 pixels greater than 0, but actually did not get the final target mask image, which may cause the child thread is not finished, the main thread will end hibernation early, start execution, This leads to a series of errors, the most obvious of which is the early release of the associated memory resource, causing the child threads that have not yet done so to access the related variables that have already freed the resource, and then an error occurs where the wild pointer appears (for image characterization: The image pointer is not NULL, but its length and width are zero or invalid).

Figure 3

Figure 3, from top to bottom, is the third red rectangle, which is the way to determine the end of the thread. The above two red rectangles are a way to run concurrently without a successful C + + thread class, and further research is needed later.

VS C + + concurrent programming

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.