Laurent Sansonetti
lsans****@apple*****
Wed Jul 4 04:52:07 JST 2007
On Jul 3, 2007, at 5:41 PM, Satoshi Nakagawa wrote: > I have another question. > Is calling performSelectorOnMainThread_withObject_waitUntilDone > safe within a Ruby thread now without the patch? Yes, the patch is required to use Ruby threads, but you can still use APIs dealing with native threads without the patch. But remember that Ruby isn't thread-safe, and therefore calling the Ruby runtime in a thread that isn't the main one will crash your application. RubyCocoa detects calls from ObjC to Ruby that are done in a different thread and tries to route the call in the main one, to avoid a crash, but this isn't optimal. This can for example cause performance regressions, or even worse, deadlocks (if the main thread is busy). So I would say that the safest way to do threading with RubyCocoa is to use the patch and Ruby threads (via the Thread class). Laurent >> On 2007/07/03, at 23:12, Laurent Sansonetti wrote: > >> This threading support is new and I'm still working on it. >> >> This exception is to warn users that using Ruby threads with >> RubyCocoa >> code inside (calls to ObjC) will crash if the Ruby interpreter has >> not >> been patched. Maybe this should just be a warning and not an >> exception, since you could potentially just do pure Ruby stuff inside >> the threads. >> >> Using performSelectorOnMainThread_withObject_waitUntilDone with >> RubyCocoa is a bit useless because RubyCocoa will always use one >> thread (because Ruby is not thread safe). If you detach a new >> NSThread >> from RubyCocoa, RubyCocoa will forward all calls to the main thread >> indirectly. >> >> Laurent >> >> On Jul 3, 2007, at 3:59 PM, Satoshi Nakagawa wrote: >> >>> Hi. >>> >>> I saw an error message, when I use Ruby threads on trunk, Tiger. >>> >>> RuntimeError: Ruby threads cannot be used in RubyCocoa without >>> patches to the Ruby >>> >>> Could you allow me to use Ruby threads on the default ruby >>> interpreter 1.8.2 of Tiger? >>> >>> In my application, I use >>> performSelectorOnMainThread_withObject_waitUntilDone >>> to communicate with the main thread from the other threads. >>> I think it's a common manner in writing GUI applications. >>> It works good even on ruby 1.8.2 of Tiger. >>> >>> I want to distribute my software to people using Tiger and the >>> default ruby 1.8.2. >>> Could you enable the threading patch only if the default interpreter >>> on the system supports the patch? >>> >>> -- >>> Satoshi Nakagawa > > _______________________________________________ > Rubycocoa-devel mailing list > Rubyc****@lists***** > http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel