Re: Question about NSThread?
Re: Question about NSThread?
- Subject: Re: Question about NSThread?
- From: "Michael Ash" <email@hidden>
- Date: Wed, 19 Nov 2008 23:10:20 -0500
On Wed, Nov 19, 2008 at 6:32 PM, Jean-Nicolas Jolivet
<email@hidden> wrote:
> One question... you wrote:
>
>> So when
>> dealing with unknown objects whose thread safety is not documented,
>> you cannot access them from multiple threads without synchronization
>> just because they present an immutable interface.
>
>
> When you talk about "accessing" these objects, do you also mean reading ?
Yes. That's all you can do with immutable objects, after all. But I am
talking about *objects* here.
> Because really all that my thread does is to read some values (i.e.
> int imagewidth, int imageheight etc)
These are integers, not objects, and thus do not qualify for the
above. As long as they're read-only for the entire lifetime of the
secondary thread, they can be accessed freely.
> Then it generates NSImages that I alloc, init, output to disk and then
> release....
>
> I've put all the "UI" modifications (status text update etc) in a separate
> method that I call using performOnMainThread:
>
> As for the rest, granted the variables like imagewidth, imageheight etc..
> are SET by my UI (they are bound to controls in IB).. .but the thread never
> actually modifies any variables/data shared with the main thread... it only
> uses those variable to generate images...
Do you also disable the GUI while the thread is running? If not, then
you have the potential to change those values in mid-stream.
> I also released and re-created my pool after each image is generated...
>
> Basically I get no errors/warning, everything seems to be working... is it
> really though?? eh... I'm still not sure...
You're right to worry. Threading mistakes won't generate any
build-time errors or warnings, and often don't show up when running
either. The worst are subtle problems which only show up rarely and
without an obvious cause when they do happen. However from what you
describe it sounds like your design has avoided the need for most of
the tricky stuff and you're in good shape.
Mike
_______________________________________________
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