• 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: NSImage from bitmap - then delete bitmap
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage from bitmap - then delete bitmap


  • Subject: Re: NSImage from bitmap - then delete bitmap
  • From: Trygve Inda <email@hidden>
  • Date: Tue, 26 Jul 2016 18:33:30 -0700
  • Thread-topic: NSImage from bitmap - then delete bitmap

> e.g.
>
> worker thread:
>
> while( self.running )
> {
> // do work
>
> window.imageRep = myResult;      // window.imageRep is (atomic, copy)
>
> [performOnMainThread: window.setNeedsDisplay];  // this is obviously
> pseudocode!
> }
>
>
> main thread, when it needs to terminate worker thread:
>
> workerThread.running = NO;
>
>
> both workerThread.running and window.imageRep are atomic properties.

I am not sure this is safe.

window.imageRep is (atomic, copy)

If the worker thread calls window.imageRep = myResult; it is possible that
the main thread is in the middle of a call like:

[[window.imageRep]
drawInRect:fromRect:operation:fraction:respectFlipped:hints:]

So when the setter (called from the worker thread) replaces the old imageRep
with a new one, the old one's retain count goes to zero and it will
disappear.

I know atomic makes the call safe as far as a vaild value is concerned, but
the main thread could call window.imageRep and get a valid value (because it
is atomic), but before it is able to use this value, the worker thread calls
the setter which causes the imageRep obtained by the main thread to be
released.

I think you'd only want to call the setter from the main thread.



_______________________________________________

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: NSImage from bitmap - then delete bitmap
      • From: Roland King <email@hidden>
References: 
 >Re: NSImage from bitmap - then delete bitmap (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Codesign assumes folder structure, fails.
  • Next by Date: Re: NSImage from bitmap - then delete bitmap
  • Previous by thread: Re: NSImage from bitmap - then delete bitmap
  • Next by thread: Re: NSImage from bitmap - then delete bitmap
  • Index(es):
    • Date
    • Thread