Monday, June 09, 2008

Concurrency and coordination runtime

Anyone who has done any amount of async programming knows that it gets out of hand pretty easily. We are good at reasoning about sequential things and async code with its callbacks within callbacks approach breaks this view and makes it hard to reason about things like correctness and boundary cases.

MSR has come up with a different programming model intended to make async i/o based programming dramatically simpler (almost feels like sequential code). It is a library on top of .net and ships as part of robotic studio. For any serious async work, this is worth investigation:
  1. MSDN article
  2. Videos

Thursday, June 05, 2008

Thread local storage leak in Compact CLR

Its pretty easy to use thread local storage on the CLR using the LocalDataStoreSlot and the Thread.Get/SetData methods. The unfortunate part is that the LocalDataStore is not freed after the thread dies .(LocalDataStore is essentially the per-thread data store which is created the first time something is set in the thread storage).

This is a big issue as memory is short on devices and apps which use threadpool to process their work items (using TLS) will end up leaking a lot as thread pool keeps spawning/exiting threads based on load.

Update: this is an issue only with netcf 2.0, it has been fixed in netcf 3.5

Monday, June 02, 2008

Generators in python

Once in a while I used generators as a simpler way of writing an iterator. I did not realize how cool and powerful generators and generator expressions they were till I read this : http://www.dabeaz.com/generators/Generators.pdf - do read it, it will be worth your time.