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: Greg Parker <email@hidden>
- Date: Thu, 19 May 2011 15:32:07 -0700
On May 19, 2011, at 3: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.
There are several cases involved here:
1. You may use an instance on any thread, as long as every use is synchronized such that only one thread uses that instance at a time.
2. You may create an instance on any thread, and must not use it on any other thread (with or without synchronization).
3. Something else.
The section "Thread-Unsafe Classes" does not distinguish among these cases. For example, NSMutableData is #1, NSAutoreleasePool is #2, and NSArchiver is #3.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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