• 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
Re: Need advice: Object ownership and threading issue, causing a rare crash.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need advice: Object ownership and threading issue, causing a rare crash.


  • Subject: Re: Need advice: Object ownership and threading issue, causing a rare crash.
  • From: Kyle Sluder <email@hidden>
  • Date: Thu, 02 May 2013 10:31:31 -0700

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 (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: Need advice: Object ownership and threading issue, causing a rare crash.
      • From: Motti Shneor <email@hidden>
References: 
 >Need advice: Object ownership and threading issue, causing a rare crash. (From: Motti Shneor <email@hidden>)

  • Prev by Date: Re: Need advice: Object ownership and threading issue, causing a rare crash.
  • Next by Date: Re: Need advice: Object ownership and threading issue, causing a rare crash.
  • Previous by thread: Re: Need advice: Object ownership and threading issue, causing a rare crash.
  • Next by thread: Re: Need advice: Object ownership and threading issue, causing a rare crash.
  • Index(es):
    • Date
    • Thread