From: Jonathan P. <jp...@dc...> - 2006-05-26 06:12:35
|
On 26 May 2006, at 6:43, Bob Aman wrote: >> Well, it's clear that I still need threading. Is it possible for me >> to use NSThread within RubyCocoa? I'd really like to avoid having to >> patch anything if at all possible. Unfortunately, neither threading technique will work without patching the ruby runtime. After that, ruby threads can be used, but calling ruby code from an NSThread is still unsafe. > I'm attempting to run Ruby code from within an NSThread. I've > basically rewritten the whole application in Objective-C, including > the threading bits, and I'm just calling out to Ruby for the scripting > stuff. However, the first 4 or 5 calls to the Ruby code work fine, > but after that, Ruby tosses a System Stack Error: stack level too > deep. It doesn't seem to matter what the method in question does. I > can even get the exception to be thrown if the method in question is > an empty method. Any ideas? Yeah, what's happening is that the real stack (as used by Objective C) gets changed when thread switches occur. Ruby thinks it's on the same Ruby thread as it was before, and discovers that the stack address has changed dramatically. It therefore concludes that there's been a stack overflow and aborts. Hopefully YARV (the up-coming Ruby VM) will resolve these issues. Sorry I don't have better news for you. You can still use NSThreads, so long as you only ever call ruby code from the main NSThread. |