So a while back we discussed implementing "broadcast"-like functionality between fiber's, each owning a TCPConnection and I was pointed at the broadcast example that uses Signal's (now called ManualEvents it seems) and rawYield(). While a bit finicky, using these with queues proved to accomplish my goals; namely being able to block a fiber on several different events (TCP read activity or pending sends implemented in a queue in the application).

However I've not got my application up and running on Linux and I'm having some crashing issues that seem like they might be related here. It's a bit hard to tell since the errors seem to happen when the GC decides to clean something up; it reports "corrupt or double freed" memory at that point, but I can't track it back to where such a thing happened. Valgrind is not particularly helpful either... it reports a bunch of irrelevant stuff from the GC's initial setup (apparently expected by the D folks and not a real issue), warns when fibers do various things (switching stacks) but otherwise doesn't give any indications of problems until the crash actually happens.

So on a whim I threw a GC.Collect in my main loop and indeed this seems to trigger the issue with more regularity and now I'm actually able to trigger something similar on Windows as well (I believe the windows GC tends to be lazier and thus I didn't see this issue during development). On windows it manifests as a libevent warning that says something like "[warn] eventdel: event has no eventbase set." or similar. After tracking a bit deeper into the vibe code, I found a potentially worrying warning in the ManualEvent destructor, namely:
"// FIXME: this is illegal (accessing GC memory)"

This seems like it might be related, although it's hard for me to be sure. Does this sound consistent with the evidence to you folks?

More importantly though, I'm left with what to do about it... I'd happily use the Win32 driver but I need this ultimately to run on Linux too and would prefer to test in both places with the same driver. (Aside: Win32 driver is still missing one thing that I need as well, namely the ability to get the remote address of a connection.) I briefly looked at Libev on Linux but even once I got that compiling it spit a bunch of warnings about unimplemented stuff in vibe at me so I got scared off :) Not sure the status or plans for that implementation.

Then I started thinking about how to avoid ManualEvent entirely... I can obviously do some sort of mutex and acquire/release on the TCPConnection itself for sending but that would block fibers that trigger sends to a client who is misbehaving, which is undesirable. I was trying to think whether there was perhaps a way to make the regular case work like this and then "detect" badness and kill the offending client, but it gets a bit messy.

Any suggestions on a way to work around this? I'm really just looking to get the application robust and working at this point ASAP (got some deadlines to hit) so non-ideal workarounds might still be reasonable, although typically such things tend to be less robust...

Thanks in advance!