• 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
Threading Problem (w/NSConnection)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Threading Problem (w/NSConnection)


  • Subject: Threading Problem (w/NSConnection)
  • From: Andrew Baldwin <email@hidden>
  • Date: Tue, 19 Mar 2002 23:16:49 -0500

I'm multithreading my app so that I perform lengthy tasks in the background. I create NSConnections between the main thread and a spawned thread. I am able to message back and forth as expected. However, I run into some problems.

The spawned thread (when it is finished with its primary task) messages the rootProxy for the connection (an object in the main thread) and passes an instance of a class of mine (SharedFolder*). It comes across the connection fine and when debugging I see that it has all the expected member data, etc.

A snippet from my code (this is the function called on the rootProxy -- i.e. there is [theProxy folderWasAdded:folder] in the spawned thread)

- (void)folderWasAdded:(SharedFolder*)aFolder
{
NSRecursiveLock* aLock = [[NSRecursiveLock alloc] init];
SharedFolder* newFolder = [[SharedFolder alloc] initWithSharedFolder:aFolder];
[fileCountProgress stopAnimation:nil];

[aLock lock];
[self addSharedFolderToList:newFolder];
[addFolderConnection invalidate];
[addFolderConnection release];
[newFolder release];
[aLock unlock];
....etc
}

As soon as the connection is invalidated, a member variable of "newFolder" is no longer accessible (If I type "print-object [newFolder folderArray]" in gdb, I get "<object raised exception generating description>" (folderArray is an NSArray). The other member variables remain valid and accessible and If I do "print-object [newFolder folderArray]" before [addFolderConnection invalidate], I have no problems.

Initially I didn't have "SharedFolder* newFolder = ..." and just used aFolder but I thought that creating a new local instance might solve my problem by some freak chance... silly me.

Any clue as to what is going wrong here? By the way, "addSharedFolderToList" has nothing to do with it... even without that line of code I have the exact same problem.

Thanks for any help,
Andrew
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: I have exorcised the deamons!
  • Next by Date: Hex IP to string
  • Previous by thread: Re: I have exorcised the deamons!
  • Next by thread: Hex IP to string
  • Index(es):
    • Date
    • Thread