I wrote a networking daemon (SMTP greylisting proxy; now unmaintained, but <plug> <a href="http://spey.sf.net" rel="nofollow">http://spey.sf.net</a> </plug>) using coroutines once.<p>Non-preemptive multitasking made reasoning about the problem way easier, because I had no concurrency to worry about, while still allowing inversion of control flow which meant that the SMTP state machines were small and simple. It worked really well.<p>...until I started getting bug reports from users about weird irreproducable crashes. After a very, <i>very</i> long time I eventually figured out that if spey was built on a system where sqlite had been compiled with pthread support, then it automatically linked in a thread-safe malloc, which tried to fetch the current thread ID, which on some versions of pthreads on some Linux architectures on some glibc versions with some kernel versions, was stored at the top of the stack. It used alignment tricks to find this.<p>So, every time something called malloc(), the libc was doing the equivalent of:<p><pre><code> threadid = *(int*) (alignup(sp, 16MB) - sizeof(int))
</code></pre>
Except my stacks weren't allocated through pthreads, so threadid ended up being garbage. Hilarity ensued.<p>I eventually rebuild the coroutine library to be a wrapper around pthreads with a big lock to ensure that only one would run at a time. Which was kind of evil, but much more reliable. (Previously I was using my own coroutine implementation based on getcontext/setcontext.)<p>So, uh. I can't remember if I had a point any more; but the pain remains.