• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Thread question (volatile needed?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Thread question (volatile needed?)
      • From: Jay Vaughan <email@hidden>
  • Prev by Date: Fwd: Re: G4 vs G3
  • Next by Date: Activating Horizontal Scrollbar in NSTableView
  • Previous by thread: Re: "Re: G4 vs G3" (G3 isn't 604ev)
  • Next by thread: Re: Thread question (volatile needed?)
  • Index(es):
    • Date
    • Thread