Amazon.com Widgets synthesize for multiple cores and threads
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 28, 2014, 07:22:41 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 7 - More on Classes
| | | |-+  synthesize for multiple cores and threads
Pages: [1]   Go Down
Print
Author Topic: synthesize for multiple cores and threads  (Read 728 times)
pdxnative
Newbie
*
Posts: 11






« on: September 09, 2010, 04:53:29 PM »

Right after the introduction of synthesize in chapter 7 Stephen makes the following comment:

"......accessor methods that are generated will be efficient and will run safely with multiple threads, on multiple machines, with multiple cores."

Can anyone elaborate on this? Why is this unique to synthesize? Specifically, why can't the same results be achieved by generating your own getters/setters manually.

No question synthesize is the better than generating your own. I am just looking for more detail on the specific advantage quoted above.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







« Reply #1 on: September 09, 2010, 07:50:10 PM »

In mukti-threaded environments, you want to make sure that one thread is not changing the value of a property while the other is retrieving it.   

This may be a little detailed here, but this is from Apple's documentation:

Quote
Properties are atomic by default so that synthesized accessors provide robust access to properties in a multi-threaded environment—that is, the value returned from the getter or set via the setter is always fully retrieved or set regardless of what other threads are executing concurrently. For more details, see “Performance and Threading.”

If you do not specify nonatomic, then in a reference counted environment a synthesized get accessor for an object property uses a lock and retains and autoreleases the returned value.

...
If you specify nonatomic, then a synthesized accessor for an object property simply returns the value directly.

Cheers,

Steve Kochan
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.