On Wed, May 1, 2013, at 05:10 AM, Motti Shneor wrote:
> Hello. 
> 
> I have two NSObject subclasses -  say MyA and MyB.
> 
> - Each MyA instance. creates and owns a MyB instance. 
> - MyB instances create an NSThread, and live their asynchronous life,
> communicating with a remote internet server, and  sometimes with their
> owner (the MyA object) who lives in the main thread.

Dumb question: can you not rely on Cocoa's built-in asynchronous
networking APIs?

> What's the best way to get out of this? How can I simply synchronize the
> "release" calls, without blocking both threads? Maybe I should restrict
> myself to retaining/releasing in the main thread only? Is there some
> syntactic Obj-C sugar to ease such things?

In such a circumstance, I would normally require MyA to use a factory
method to construct instances of MyB, and have that factory method add
the MyB instances to an object pool. When MyB operations are cancelled,
they perform their cleanup and message the thread they were created on
to remove themselves from the pool. Using dispatch queues should
simplify this quite a bit.

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to