Home > Java > javaTutorial > Is multithreading concurrent or parallel?

Is multithreading concurrent or parallel?

(*-*)浩
Release: 2019-06-19 11:28:40
Original
9388 people have browsed it

The so-called process (process) is a memory area that contains certain resources. The operating system uses processes to divide its work into functional units. One or more execution units contained in a process are called threads. A process also has a private virtual address space that can only be accessed by the thread it contains.

Is multithreading concurrent or parallel?

#A thread can only belong to one process and it can only access resources owned by that process. When the operating system creates a process, the process automatically applies for a thread called the main thread or the primary thread. (Recommended learning: Java Video Tutorial)

The processes do not run at the same time in the true sense, but run concurrently.
A process has at least one thread. The division scale of threads is smaller than that of processes, making multi-threaded programs highly concurrency. In addition, the process has an independent memory unit during execution, and multiple threads share memory, thus greatly improving the running efficiency of the program.

The difference between a thread and a process during execution is that each independent thread has an entrance for program running, a sequential execution sequence, and an exit for the program. However, threads cannot execute independently and must exist in the application program, and the application program provides multiple thread execution control.

From a logical point of view, the meaning of multi-threading is that in an application, multiple execution parts can be executed at the same time. However, the operating system does not regard multiple threads as multiple independent applications to implement process scheduling and management and resource allocation.

Multiple threads or processes running "simultaneously" is just a sensory manifestation. In fact, processes and threads run concurrently. The thread scheduling mechanism of the OS divides time into many time segments (time slices) and distributes them as evenly as possible to the running programs. The thread or process that obtains the CPU time slice can be executed, and other Then wait. The CPU switches back and forth between these processes or threads. On the micro level, all processes and threads are stop-and-go, but on the macro level, they are all running. This phenomenon of all running is called concurrency, but it does not occur at the same time in the absolute sense.

More Java-related technical articles , please visit the Java Development Tutorial column to learn!

The above is the detailed content of Is multithreading concurrent or parallel?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template