> 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 (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