Simple principles of Multithreading

Source: Internet
Author: User

I believe that we often hear about processes and threads. Of course, this must be useful.

What is a process?

Books are processes. You will find that my computer runs multiple processes.

For previous single-core computers (it can only execute one process at a time. Why can we listen to songs and watch movies? It's because the cpu is switching fast !)

Then, for multi-core systems, you can run multiple processes at the same time.

As mentioned above, the memory between processes is independent of each other!

The following describes the thread:

The thread is the minimum Execution Unit of the process. This is a little professional, or a simple figure.

I have read more code!

Main (}
// This code is obviously completed in a single thread!

The following figure illustrates the problem.

 

The following is a multi-threaded Execution Code:

Main (Thread thread = Thread (run); thread. Start (); (I =; I <; I ++}
Let's take a look at the execution result! Part, followed by the output

The figure shows that it is not continuously output, and the for in the main method is still executed
You may think that it is the effect of creating a thread. Why is this effect?
See the figure below:


 

 

The above is a summary of my work and study. The thread principle calling is mainly reflected in this notebook (opening up a new thread stack memory !)

Of course there are still many shortcomings. Do not ping the shortcomings. Please point out!

 

 

 

Related Article

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.