Thread Safety - A Theoretical Question
Thread Safety - A Theoretical Question
- Subject: Thread Safety - A Theoretical Question
- From: André Berg <email@hidden>
- Date: Mon, 12 Oct 2009 22:47:15 +0200
Hi,
I am designing my first real class and I am wondering about thread
safety. I have read the Cocoa Fundamentals and also the Threading
Programming Guide but there was one question forming in my head which I
couldn't quite find an answer for. I guess it is something that class
designers deal differently with.
My class internally doesn't use any threads at all (well apart from an
NSTask ivar and readInBackgroundAndNotify). The only scenario I can
think of that would be dangerous is if in the calling code (the code
from the user of my class) there are two threads which could
simultaneously access the same instance of my class.
In that case is it my responsibility to guard all access to my class'
thread unsafe ivars (like mutable objects for example) or is it the
responsibility of the user of my class to guard all access to my class'
instances in his code?
With regards to this, should I care about thread safety at all? If you
are designing a class, even without any concurrency in it at all, where
do you decide to worry about thread safety in code outside your reach?
I know this is a somewhat loaded question, but I do appreciate any
pointers and one-liners.
Thanks a lot for reading!
Cheers,
André
_______________________________________________
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