Re: Seeking advice on NSLock usage
Re: Seeking advice on NSLock usage
- Subject: Re: Seeking advice on NSLock usage
- From: Jeremy Dronfield <email@hidden>
- Date: Mon, 13 Dec 2004 22:07:37 +0000
On 13 Dec 2004, at 7:48 pm, Guy English wrote:
On Mon, 13 Dec 2004 11:54:51 +0000, Jeremy Dronfield
<email@hidden> wrote:
On further reflection, I may offer both approaches as a user option.
If
my search thread uses the original model instance, the practical side
effect is that the user can "tune" their search criteria on the fly,
while a search is in progress. In some situations I could see this
being a useful option.
Uh ... wait a second. If your search is going to be running in another
thread and you want to alter the parameters while it's running then
you'll definately need a lock. Changing objects that a thread may be
reading from is bad mojo. Consider:
main thread:
[newCriteria retain];
[criteria release];
search thread then decides to run:
if ( [criteria isEqualTo: @"blah"] ) // app explodes here 'cause
criteria has been released.
main thread:
criteria = newCriteria; // too little to late.
Make sure you put locks around stuff that's going to be accessed by
both threads.
Yes, I know. What I said was, I decided to use a copy instead of locks
– but on further reflection I'm considering doing both.
Regards,
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden