Re: Thread question (volatile needed?)
Re: Thread question (volatile needed?)
- Subject: Re: Thread question (volatile needed?)
- From: Mason Mark <email@hidden>
- Date: Fri, 13 Jun 2003 09:01:27 -0700
--On Wednesday, June 11, 2003 2:07 PM +0200 Manfred Lippert <email@hidden>
wrote:
@interface myClass {
NSLock *lock;
id object;
...
}
...
@end
@implementation myClass
...
- (void) someMethod {
...
[lock lock];
[object doSomething];
[lock unlock];
...
}
...
@end
"object" is allocated from other methods called by other threads, and may
often change during runtime. These allocations are also made "locked", of
course. So the pointer to "object" (the id) may change during runtime. My
question: Can I be sure that the pointer to "object" is surely read
_after_ my [lock lock] statement? Or could it be that some compilers (or
with some compiler options) this reading may be made before the locking
statement? Is it necessary or useful to declare
volatile id object;
instead?
--On Wednesday, June 11, 2003 5:06 PM +0200 Jay Vaughan
<email@hidden> wrote:
His thread problem, I surmise (correct me if I'm wrong), had more to do
with the fact that he's not properly treating his locks properly and the
critical section he thought is protected is not protected at all ...
What thread problem are you referring to here?
Seems to me that the question was whether or not he had a thread problem,
and the answer is no. As Marcel explained, it is unnecessary to mark the id
volatile, and there should be no problem.
Another thread attempting to acquire the NSLock won't fail, it will block.
--
Mason Mark
Five Speed Software, Inc.
_______________________________________________
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.