Why do swoole use implicit collaborations now? Instead of yield-style collaboration?

one of the main advantages of co-programming over multithreading is that it actively gives up CPU, rather than CPU preemption.
in this way, many locks can be avoided in order to avoid preemptive locks.

but swoole chooses implicit co-programs, so that for upper-level code, CPU is still preempted by other co-programs (rather than through yield, etc.), which may lead to many problems caused by preemption.
for example, the status of half of the, mysql client queried by mysql and redis has been modified by other protocols, and so on.

I don"t know why swoole uses implicit coordination, and is there a hole in this approach?

Mar.03,2021

I think it just makes the program more convenient to use, while using yield is rather obscure to implement.

For the implementation of

yield , please see Bird blog: implementing multitask scheduling in PHP using cooperative routines

.

if you manage your own programs and manually yield , you need to determine for yourself whether the event is ready or not. At this point, Swoole needs to expose more C underlying API for you to use.

and you manage yield collaborators yourself, if you forget resume , it's easy to cause memory leaks.

Menu