• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
GCD dispatch workers and termination
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GCD dispatch workers and termination


  • Subject: GCD dispatch workers and termination
  • From: Jason Harris <email@hidden>
  • Date: Sun, 27 Mar 2011 20:27:12 +0200

Hi All,

Following on from some of the issues I had and people raised about NSTasks intermittently failing I now have the following issue. When I profile my application (MacHg) in threads, I can see a large number of DispatchWrokers which are created but never seem to exit. In an effort to track down whats going on I can create a very small project and see the exact same behavior.

To replicate this in a dummy app one can go and create a new XCode document based cocoa application, and add the following method:

- (void) doWorkerLaunches
{
    for (int i = 1; i <50; i++)
    {
        dispatch_async(dispatch_get_global_queue(0,0), ^{
            NSTask* task = [[NSTask alloc] init];
            [task setLaunchPath: @"/bin/ls"];

            NSArray* arguments = [NSArray arrayWithObjects: @"-l", @"-a", @"-t", nil];
            [task setArguments: arguments];

            NSPipe* pipe = [NSPipe pipe];
            [task setStandardOutput: pipe];

            NSFileHandle* file = [pipe fileHandleForReading];

            [task launch];
            [task waitUntilExit];

            NSData* data = [file readDataToEndOfFile];
        });
    }
}

Then I change windowControllerDidLoadNib like so:

- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
    [super windowControllerDidLoadNib:aController];
    [self performSelector:@selector(doWorkerLaunches) withObject:nil afterDelay:2.0];
}

So basically 2 seconds after launch I go do a lot of parallel dispatched tasks of launching ls.

I turn on garbage collection in the project. (This doesn't seem to make any difference one way or the other.) Then I build the project. Then run this project in instruments with the "Threads instrument" and I get lots of DispatchWorkers that didn't terminate.

The screen shot of the non-terminated DispatchWorkers is here: http://jasonfharris.com/files/misc_snippets/threadsDispatchWorkers.png
I have zipped this simple project up and put it here: http://jasonfharris.com/files/misc_snippets/gcdGroups.zip

Can anyone shed some light on why these DispatchWorkers are not terminating?

Thanks!
   Jason_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: GCD dispatch workers and termination
      • From: Ken Thomases <email@hidden>
    • Re: GCD dispatch workers and termination
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: copyPath:toPath:handler: more reliable than copyItemAtPath:toPath:error: ???
  • Next by Date: Re: GCD dispatch workers and termination
  • Previous by thread: Pasting a PDF image in text: NSCGImageSnapshotRep and upside down drawing
  • Next by thread: Re: GCD dispatch workers and termination
  • Index(es):
    • Date
    • Thread