[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: coroutine vs threads
- From: Florian Weimer <fw@...>
- Date: Sun, 17 Jul 2011 11:53:39 +0200
* Gaspard Bucher:
> The Lua state processes a single operation at a time (no concurrency).
> Example of such operations (for the same Lua state) can be:
> 1. Receive message from network ===> update state ==> post reply
> 2. Receive notification from OS (file changed, mdns discovery, etc)
> 3. Receive a command from GUI (redraw window, mouse event, keyboard event,
> etc)
> 4. Trigger function from scheduler (pthread based timer)
This description is already heavily titled to an event-based approach.
You don't need coroutines at all for that.
The question of threads or coroutines arises when the reaction to an
event triggers further external interaction, such as posting messages
to several peers and acting on their replies. If this is not
necessary, it's probably best to stick to the event-based approach.
GUIs are a bit of a thorny issue. Events certainly have their
weaknesses, but it's a model that's been used for a while, and it
works with several underlying implementations.