[MacRuby-devel] Possible bug launching an NSTask from within and NSOperation subclass

Leigh Caplan texel1 at gmail.com
Tue Jul 20 11:13:15 PDT 2010


Hi Laurent,

This was basically a direct port of a pure ObjC application that works correctly in this same situation. I just went and implemented this reduced case in ObjC, and interestingly enough, I *can* reproduce the issue. Here's the app:

http://github.com/texel/NSOperationCocoaDebug

Now, this version works, but it appears that the *reason* it works is due to the release message in this line:
http://github.com/texel/NSOperationCocoaDebug/blob/master/TaskPerformer.m#L23

If either the release message or the waitUntilExit message are left out, the NSOperation thread's runloop never exits. Additionally, if you compile and run this garbage collected, you get the same behavior.

Also, notice that I'm not using the main runloop, I'm calling NSRunLoop.currentRunLoop which returns the runloop for the current thread, and creates one if it doesn't already exist.

There must be some interaction here between the runloop and the task that I'm not fully understanding. Note that an identical task launched from the main thread seems to work fine (obviously the thread doesn't have a similar exit condition, but it doesn't completely block either).

Thanks for helping me solve this mystery :)

Leigh


> Hi Leigh,
> 
> I had a quicklook at the code. I am not sure if running the main runloop from an NSOperation is the right thing to do here, I suspect that's what's causing the problem. It might be interesting to use the NSTask's notification functionality here or try to rewrite this code in pure ObjC and see if the problem persists.
> 
> Laurent
> 
> On Jul 19, 2010, at 8:23 PM, Leigh Caplan wrote:
> 
>> Hi there,
>> 
>> I've encountered what I believe to be a bug, but I'd like more eyes on it to make sure I'm not doing something wrong. I've set up a simple application, with one controller that has a reference to an NSOperationQueue. When a button is pressed, the controller queues up an NSOperation subclass, which schedules its run loop, then fires off a call to perform an NSTask. The task simply launches /bin/sleep for 2 seconds.
>> 
>> You can follow along and try for yourself here:
>> http://github.com/texel/NSOperationDebug
>> 
>> Here's the bug? when the NSTask is launched, regardless of whether or not waitUntilExit is set on it, and regardless of whether or not the task actually exits, it seems to block the NSOperation's run loop indefinitely. I had this issue in another application, but this is the most basic case I can think of to reproduce it.
>> 
>> If I'm doing something wrong, then awesome. Any help would be appreciated. If not, then I'd be glad to file a bug report.
>> 
>> Thanks!
>> Leigh
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100720/6b345841/attachment.html>


More information about the MacRuby-devel mailing list