Re: "Use them from only one thread at a time"
Re: "Use them from only one thread at a time"
- Subject: Re: "Use them from only one thread at a time"
- From: Justin Anderson <email@hidden>
- Date: Thu, 19 May 2011 18:32:45 -0400
I think there's actually a typo in the second sentence. If you look in the Thread-Safe section above that, it refers to instances: "The following classes and functions are generally considered to be thread-safe. You can use the same instance from multiple threads without first acquiring a lock."
For the documentation to contrast classes with thread-safe instances against classes which are entirely thread-unsafe would not make sense. I think it's supposed to be: "In most cases, you can use **instances of **these classes from any thread as long as you use them from only one thread at a time."
And I don't believe Jerry's rewording is correct. It looks like everything in the unsafe list is either mutable or maintains some internal state which would get trampled by concurrent calls. You should be able to share thread-unsafe instances with other threads, just as long as only one thread is using them at a time.
Justin
On May 19, 2011, at 6:06 PM, Sean McBride wrote:
> On Thu, 19 May 2011 14:31:23 -0700, Quincey Morris said:
>
>> On May 19, 2011, at 13:56, Sean McBride wrote:
>>
>>>> Would it be correct to restate it
>>>> like this…
>>>>
>>>> "In most cases, although you can allocate instances of these classes on
>>>> any thread, each instance must receive messages only from the thread
>>>> which allocated it."
>>>
>>> I believe so.
>>
>> I don't believe so.
>
> Did you look at the classes listed under that section?
>
> <http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/
> Multithreading/ThreadSafetySummary/ThreadSafetySummary.html>
>
> NSMutableData is one. If Apple's wording is correct, that means I can't
> create two threads, each of which creates and manipulates its *own*
> NSMutableData instances (but doesn't share these objects with other
> threads!). That just seems unlikely to me. How could you ever use
> NSMutableData on a non-main thread if so? Who's to say some OS-created
> thread is not also using NSMutableData?
>
> I do think Jerry is right; they mean you can create NSMutableDatas on
> any thread, as long as you don't share the instances with other threads.
_______________________________________________
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