yet another retain/release question...

Member
Posts: 208
Joined: 2005.04
Post: #1
Sorry for flooding the forum with these types of questions... you guys have been über-helpful and I really appreciate it! Smile

on to the question...

Are the retain and release methods thread-safe? That is, do I need to lock around calls to them if there is a chance that two or more threads might try to call an object's retain or release method at the same time? How about autorelease?

Thanks,

Andrew
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #2
Read this and/or this. Generally, as long as you're not mutating objects from concurrent threads, you should be safe (if I'm not wrong, which I might very well be. Wink ).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Wow, there's a lot more explicitly stated as thread-safe than I recall. Anyone know whether my memory's faulty, or whether some of that stuff is new in recent versions of Mac OS X?
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #4
Thanks for the links Fenris Smile
I actually came across both of those pages a while back, but then only gave them a quick read. Now, after reading them in detail, it does seem as though Apple synchronized around the code which modifies the retain count ivar of an immutable object. It would be nice if they could give a direct answer though. Maybe I'll ask this question on the Apple's cocoa-dev list.

I found something else which might help me out (if I'm deciphering it correctly). This is from a link off the Thread Safety Guidelines page regarding Core Foundation:

Quote:You cannot rule out, for example, indeterminate behavior resulting from retaining an object obtained from a collection. The collection itself might be freed before the call to retain the contained object is made.

I'm not exactly sure what they mean by this though. Are they talking about an explicit call to CFRetain() or an implicit call?

Keith, I seem to remember there being a shorter list of thread safe classes as well. It says the page was last updated on 2005-03-03.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Alloc/Release question Neocron 5 3,390 Feb 5, 2009 04:08 PM
Last Post: daveh84
  retain count weirdness Andrew 12 5,271 May 29, 2005 10:55 PM
Last Post: Fenris