M
M
MaM2017-03-11 23:07:43
Programming
MaM, 2017-03-11 23:07:43

Coroutine, what are they for?

Actually for what? There are conceptual differences between coroutines in python and c++ or Lua or c.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nirvimel, 2017-03-12
@MaM

Coroutines implement cooperative multitasking between green_threads within the same process (the OS has no idea about all this, its threads have nothing to do with it). At the moment of coroutine "call", "green" tasks are switched instead of actually calling the function. Tasks that are waiting for I/O to complete receive control if their I/O has completed (or timed out).
What is all this for? OS threads are too heavy. They take up a lot of stack (memory). Their creation/destruction takes time. Switching between them occurs through the OS kernel (too slow). A large number of simultaneously active threads can hang the entire system. In real applications/servers, the number of threads is typically measured in tens of maximum ("green" threads can be tens of thousands). To overcome the C10K problem, there is a need to switch to asynchronous programming with "green" threads instead of OS threads. One problem remains - task switching (which must now be done manually); Who should do it and when?
This switch can happen in the io_loop (I / O loop) of a special library that is responsible for the asynchrony of the entire application (for example, asyncio in python). And in order for the flow of control from the code to return to the io_loop, you need to replace direct function calls with asynchronous "calls" to the coroutines.
In the early 90s, preemptive multitasking on 80386 processors seemed like a completely breakthrough technology. Who would have thought that in 20-25 years we will (in a sense) return back to cooperative multitasking.

A
Alexander Pozharsky, 2017-03-11
@alex4321

For example, you can implement any kind of asynchronism on them (for example, while we are waiting for a response from such and such a service, we can process a new request in the same thread). Anything is better than callback hella from javascript.

S
Stalker_RED, 2017-12-17
@sanke46

And he doesn't move. The image in the block needs to be better centered.
https://jsfiddle.net/3bsuLxuw/

A
Alexander Kositsyn, 2018-01-10
@alex_keysi

Set image-box position to absolute. You're animating on the parent of the picture, so it's also spinning. You need to take it out of the flow so that the descendant of the big-line does not animate.
Or put big-line as a neighbor for image-box.
Then spin will only spin it.
You see, spin rotates the big-image element and all its descendants, and this is the image-box

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question