进程 线程 子进程 About Processes,Threads,Coroutine
here is a story to explain what Processes,Threads,Coroutine is,and
understanding of parallel and concurrent programming
1.Parallel and Concurrent
- Parallel: simultaneous execution of multiple tasks
- Concurrent Multiple tasks are executed alternately on the same processor
2.Processes
mean program in progress
strengths and weaknesses
strengths:
- more stability and safety
weaknesses:
- require more resource overhead when processe swiching
- IPC is complex and time-consuming
3.Threads
Thread contained in process,also called lightweight process
if Processes as a hight speed road, threads like the car, they make one processes can execute multiple task
strengths and weaknesses
strengths:
- require less resource overhead when threads swiching
weaknesses:
- not stable enough,data might be lost,deadlock
4.Coroutine
coroutine is lightweight threads
function echoTimes($msg, $max) { |
strengths:
- high execution efficiency
- shared resource,no need lock
for multi-core cpu,use multiple processes and coroutine,can get better performance
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 👋Blog!
评论