lundi 23 mars 2015

Why should we expect user-space coroutines to be lighter than OS threads?


I have heard it said that managing concurrent TCP connections using user-space coroutines uses less resources per open connection than using an OS thread per connection.


Actually, OS threads and coroutines are essentially different ways of representing the same thing: a combination of control and state.


An OS thread stores:



  • A pc counter (representing control)

  • A stack pointer + other registers (representing state)


A coroutine requires:



  • A function pointer (representing control)

  • An environment pointer (representing state)


Why should we believe user-space coroutines to be a more resource-efficient approach?





Aucun commentaire:

Enregistrer un commentaire