Re: Techniques for thread communication
Re: Techniques for thread communication
- Subject: Re: Techniques for thread communication
- From: Eric Scharff <email@hidden>
- Date: Mon, 8 Sep 2003 11:43:40 -0700 (PDT)
--- Douglas Davidson <email@hidden> wrote:
>
Yes, of course you can do this. You just need to be sure to
>
lock
>
around all accesses to the shared data structure, or use some
>
other
>
strategy to make sure that it is in a consistent state for all
>
threads.
WorkerThread never accesses result, it works on workingCopy. So
somewhere in my code I do
while (working) {
workingCopy = [[Result alloc] init];
// Does the work
[self setResult: workingCopy];
[workingCopy release];
}
-(void)setResult: (Result *)newResult {
[myLock lock];
[result release];
result = [newResult retain];
[myLock unlock];
}
Is this the right way to write the getter?
-(Result *)result {
Result *r;
[myLock lock];
r = result;
[myLock unlock];
return r;
}
Is this over-paranoid? can one assume the assignment is atomic?
Thanks for all your help,
-Eric
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.