• 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
Re: Techniques for thread communication
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Techniques for thread communication


  • Subject: Re: Techniques for thread communication
  • From: Eric Scharff <email@hidden>
  • Date: Mon, 8 Sep 2003 11:43:40 -0700 (PDT)

--- Douglas Davidson <email@hidden> wrote:
> Yes, of course you can do this. You just need to be sure to
> lock
> around all accesses to the shared data structure, or use some
> other
> strategy to make sure that it is in a consistent state for all
> threads.

WorkerThread never accesses result, it works on workingCopy. So
somewhere in my code I do

while (working) {
workingCopy = [[Result alloc] init];
// Does the work
[self setResult: workingCopy];
[workingCopy release];
}

-(void)setResult: (Result *)newResult {
[myLock lock];
[result release];
result = [newResult retain];
[myLock unlock];
}

Is this the right way to write the getter?

-(Result *)result {
Result *r;

[myLock lock];
r = result;
[myLock unlock];
return r;
}

Is this over-paranoid? can one assume the assignment is atomic?

Thanks for all your help,

-Eric

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
_______________________________________________
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: Techniques for thread communication
      • From: email@hidden (Peter Robinson)
    • Re: Techniques for thread communication
      • From: Douglas Davidson <email@hidden>
References: 
 >Re: Techniques for thread communication (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: Techniques for thread communication
  • Next by Date: Re: Techniques for thread communication
  • Previous by thread: Re: Techniques for thread communication
  • Next by thread: Re: Techniques for thread communication
  • Index(es):
    • Date
    • Thread