From: Nobuyoshi Nakada Date: 2007-05-16T11:46:16+09:00 Subject: Re: rb_yield(), semaphores and 'break' Hi, At Wed, 16 May 2007 11:25:05 +0900, Pete wrote in [ruby-talk:251756]: > Here's the sitch... I'm working on an extension to handle real-time > MIDI, and my concept is to have an 'each' method for the MidiIn class > that will just feed events to a block as they arrive. This is implemented > by the 'each' (C++) function making the block available to a callback > function, which is itself called by the Midi handler for each arriving > event, and does a rb_yield(). The original function is meanwhile just > sitting on a semaphore, and will return when that is released. What semaphore? ruby's or C++'s? > This all works fine, as the semaphore can be released either by a > particular yield return value or by a timeout, *unless* there is > a 'break' in the invoked block. The base problem is that -- although > I can catch the break with an 'ensure' for instance -- the top-level > 'each' is still sitting on the semaphore until that is released, > but as the break has *already* popped the stack, when that function > *does* terminate it just segfaults! Have you tried rb_ensure()? -- Nobu Nakada