Concurrent with parallel

A concurrent and parallel

The concept of multi-tasking:

1. Simply put, it is the operating system can run multiple tasks simultaneously.

Concurrency: refers to the number of tasks unnecessary cpu core number, through a variety of task scheduling algorithms operating system to achieve multiple tasks
"with" execution (in fact, there is always a task is not executed because the task switching speed very fast, looks performed together only)

example: the equivalent of several students, while questioning a teacher, the teacher can only be one answer.


Parallel: Refers to the number of tasks is less than equal to the number of cpu core, that really perform tasks with

examples: the equivalent of several students, at the same time to ask questions. More teachers while giving each student answers

Summary: The true parallel multi-task can only be achieved on multi-core cpu, but due to the number of tasks far more than the cpu core
number, so the operating system will automatically turn many tasks scheduled for execution on each core

2. Synchronous Asynchronous

Sync: refers to the thread when accessing a resource, access to resources will be executed after return results of other operations (do first
something, do something)
Asynchronous: as opposed to synchronous, refers to the thread again when accessing a resource whether or not to return the results achieved are the next step; when resources have returned results
will be notified thread.

Second, thread

1, threading module describes
the python Thread module is a relatively low-level module, Python's threading module is Thread made some packaging
can more easily be used

to create a thread object: threading.Thread (target = func)
parameter specifies the target thread execution task (function)

the thread class provides the following methods:

method: Description
run () method to indicate the active threads
start () to start the thread activity
join () to set the main thread wait time down the seconds before execution, time defaults to sub-thread ends, a plurality of sub-threads
value between the superimposed
isAlive () returns the thread is active
getName () returns the thread name
threading.currentThread (): returns the currently executing thread
threading.enumerate (): returns the running of all thread (list). It refers to the thread starts running, before the end, does not include start
the thread before and after the termination of
threading.activeCount (): Returns the number of threads running

Guess you like

Origin www.cnblogs.com/666666pingzi/p/10964555.html