Multithreading benefits and drawbacks

Before you create a thread to explain basic concepts:
Serial and parallel:

Serial (synchronous) : mimic human work, the next thing to do after a done thing (such as wearing clothes on the toilet)
parallel (asynchronous) : do one thing when, without waiting for the thing done, do the next thing (such as dinner time but also can watch the video play phone)

Threads and processes:

Thread : CPU scheduling and distribution of basic unit, the basic need of system resources, has only a little essential resource at runtime (It takes up about 1M memory)
Process : the first performance of the application process
relationship between threads and processes : a program must have a process, a process has at least one thread, you may also have multiple threads.

Multithreading benefits and drawbacks:

Multithreading can reduce the complexity of the code, a serial work into a parallel, but if used improperly, it will reduce efficiency, consumption performance.
For example:
a single-core CPU, when executing multiple threads:
a man digging in the cave, it is clear that if two people from two dug this the fastest and lowest time-consuming, but now only one person, if multiple threads, it will appeared to start on the left to dig for two days, then went to the right to dig for two days, this would be very time consuming, since the middle of the journey will be time-consuming (Switching between threads)
But if caught in a single-core CPU IO stream operations, the use of multiple threads, it will improve performance, so be sure toUse appropriate

Lack of study time, too shallow knowledge, that's wrong, please forgive me.

There are 10 kinds of people in the world, one is to understand binary, one is do not understand binary.

Published 71 original articles · won praise 54 · views 420 000 +

Guess you like

Origin blog.csdn.net/weixin_43326401/article/details/104095697