torsdag den 8. marts 2012

A Microscopic Event Lib

Many years ago, an extremely able colleague of mine introduced me to what could be called Asynchronous Programming. From GUI programming, we know the notion of callback registering and execution. When applying this principle to streams and time as well, programs can handle (seeming) concurrency just as responsive as using threading. I have never looked back ..

Although I rate myself as pretty good at managing preemptive concurrency, I *hate* the added complexity of protecting all shared data. And last but not least, the flow of execution is much easier to grasp when all callbacks run to completion before falling back into the main loop.

The catch of course, is that *everything* needs to asynchronous. Ie. all operations must complete in a short amount of time, or be arranged so that a callback is called upon completion. Also factoring everything into callbacks can be tedious in a language like C that doesn't have anonymous functions, let alone closures.

This of course has been realized by brighter minds already, and that is why libevent exists. However this is a relatively heavyweight, certainly in embedded Linux where megabytes of storage can be counted on one hand.

And this is why the micro event lib (libuevent) came into being. The tediousness of C is addressed with a Lua binding. Lua of course has closures, so this style of coding becomes next to effortless.

Go check it out on GoogleCode ..


Ingen kommentarer:

Send en kommentar