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) {
for ($i = 1; $i <= $max; ++$i) {
echo "$msg iteration $i\n";
yield;
}
}

function task1()
{
yield from echoTimes('bar', 5);
}

strengths:

  • high execution efficiency
  • shared resource,no need lock

for multi-core cpu,use multiple processes and coroutine,can get better performance