Thread question (volatile needed?)
Thread question (volatile needed?)
- Subject: Thread question (volatile needed?)
- From: Manfred Lippert <email@hidden>
- Date: Wed, 11 Jun 2003 14:07:23 +0200
Hi,
if I have an application that runs different threads and I have the
following situation:
@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?
Thanx,
Mani
_______________________________________________
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.