0, the concept of the process
Three states: Ready, running, blocking
Ready: When the process has been assigned all the necessary resources except the CPU, the process state becomes ready as long as the processor is available for immediate execution.
Execute/Run (Running) state: When the process has acquired a processor, its program is executing on the processing machine, at which time the process state becomes the execution state.
Blocking (Blocked) state is executing a process that discards the processor while waiting for an event to occur and is blocked. There can be many events that cause a process to block, such as waiting for I/O to complete, requesting that the buffer is not satisfied, waiting for a letter (signal), and so on.
Synchronization: When a task is completed to depend on another task, the dependent task can be completed only after the task is completed, which is a reliable task sequence. Either success succeeds, failure fails, and the state of the two tasks remains the same.
Async: There is no need to wait for a dependent task to complete, just to notify the dependent task to complete what work, the dependent task is immediately executed, as long as the complete task is completed. The task sequence is unreliable, as the dependent task is ultimately completed, and the task that relies on him cannot be determined.
A process is the smallest resource allocation unit in a computer.
The base is open:
1 Import Time2 fromMultiprocessingImportProcess3 4 deff (name):5 Print('Hello', name)6 Print('I am the child process')7 8 if __name__=='__main__':9p = Process (Target=f, args= ('Bob',))Ten P.start () OneTime.sleep (1) A Print('The main process is executed.')
the opening of a child process
1 D:\Python36\python.exe e:/python/ draft paper. PY2Hello Bob3 I am a child process 4 The main process is executed. 5 6 Process finished with exit code 0
Results
Lock--Mutual exclusion lock
Semaphore--Lock + counter
Event--python thread events are used for the main thread to control the execution of other threads, and the event provides three methods set, wait, clear.
Event handling mechanism: global definition of a ' flag ', if the ' flag ' value is false, then when the program Event.wait method will block, if the ' flag ' value is true, then the Event,wait method will no longer block.
Clear: Set ' Flag ' to false.
Set: Sets ' Flag ' to true.
1. Threads
2. Thread Efficiency test
3. Data isolation Test
4. Main thread and sub-thread
Python_ thread, thread efficiency test, data isolation test, main thread, and child thread