(v) Multithreaded programming

Source: Internet
Author: User

First, Multithreading introduction
1. Parallel execution mechanism under operating system
(1) Parallelism means that multiple tasks are executed at the same time. Parallel parallelism and macroscopic parallelism.
(2) macro-parallel is from a long period of time (relative to people), multiple tasks are carried out simultaneously, micro-parallel is really in parallel execution.
(3) The operating system requires the implementation of macro-parallel. There are 2 cases of parallelism on the macro level: the first is the micro-serial, the second is the microscopic parallelism.
(4) theory, the single-core CPU itself has only one core, and can only execute an instruction, this CPU can only achieve macro-parallel, the microscopic must be serial. Parallelism on the micro requires multi-core CPUs. Multiple cores in a multicore CPU can execute multiple instructions at the same time, so that parallelism can be achieved at the micro level, thereby increasing the degree of parallelism on the macro level.

Ii. differences and linkages between processes and threads
(1) Processes and threads are two different software technologies for the operating system, with the aim of achieving macro parallelism (the popular point is that multiple programs run simultaneously on a single machine, achieving the effect of seemingly parallel execution on a macro scale).
(2) Processes and threads differ in the principle of implementing parallel effects. And this difference is related to the operating system. For example, in Windows, the process and thread differences are large, and the process and thread differences are small in Linux (Linux threads are lightweight processes).
(3) Whether it is multi-process or multi-threading, the ultimate goal is to implement parallel execution.

Three, the advantage of multithreading
(1) Many more processes in the previous years, multi-threading began to use much in recent years.
(2) The modern operating system design takes into account the multi-core CPU optimization problem, to ensure that: when the multi-thread is running, the operating system will prioritize multiple threads in multiple cores to run separately. So the multi-core CPU provides a perfect operating environment for multi-threaded threads. So there are great benefits to using multi-threaded threads on multi-core CPUs.

Multi-core CPU running multi-threaded program, to pay attention to multi-thread synchronization, the communication between the threads use some shared variables, these shared variables need to be synchronized, multiple threads can not access the same shared variable at the same time, access to request before, gain access, and then not be used to obtain access rights, and then operate , this is the problem of multithreading synchronization and locking.

(v) Multithreaded 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.