Re: @synchronized question
Re: @synchronized question
- Subject: Re: @synchronized question
- From: Mel Walker <email@hidden>
- Date: Mon, 24 May 2004 13:06:20 -0600
On May 24, 2004, at 12:11 PM, Clark Cox wrote:
On May 24, 2004, at 12:15, Mel Walker wrote:
-(void)doSomething {
@synchronized(myTextView) {
...
}
}
or should I do something like this:
-(void)doSomething {
@synchronized(self) {
...
}
}
Which one you use depends on which object you're trying to protect
access to. So, for instance, if you have another method:
-(void)doSomethingElse
{
@synchronized(self)
{
//Something that may have nothing to do with myTextView
}
}
This could be blocked if the (self) version of doSomething is
currently running, but won't be blocked if the (myTextView) version is
running. Either way, you should try to be consistent.
Thanks for that explanation. Let's see if I've got it --
@synchronized(someObject) {}
is the equivalent of:
{
[someObjectsLock lock];
// use someObject here
[someObjectsLock unlock];
}
correct? Which is better to use?
--
Mel Walker <email@hidden>
_______________________________________________
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.