• 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: NSThread Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSThread Question


  • Subject: Re: NSThread Question
  • From: "John W. Whitworth" <email@hidden>
  • Date: Wed, 24 Apr 2002 00:46:16 +0100

Once you start using threads, issues of thread safety are raised. Any visual interface updates should be done from the main run loop. A thread should call a selector in the main run loop via distributed objects. Also be aware of data integrity issues if more than one thread is reading and writing to the same object.

John Whitworth

Thank you for your help. The example code you suggested won't compile with
my PB 1.1.1. Anyway I have found a line of that sample very useful, so I
made this (it works very fine! - If you think some error could occur with
this code in the future, please advise):

- (IBAction)executeLoop
{
if(isRunning == YES){
// isRunning is a variable instance of this class
isRunning = NO;
return;
}
isRunning = YES;
[NSThread detachNewThreadSelector:@selector(processTheItems)
toTarget:self withObject:nil];
}

- (IBAction)processTheItems
{
int i;
// gItemsToDoArray is a variable instance of this class
for(i = 0; i<[gItemsToDoArray count]; i++){
if(isRunning == NO) break;
[self processSingleItem:[gItemsToDoArray objectAtIndex:i]];
}
// This shows an alert telling how much items
// were been processed
[self showReport:i];
}

Thanks Drew!

--
Lorenzo Puleo
mailto: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.
_______________________________________________
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.

References: 
 >Re: NSThread Question (From: Lorenzo Puleo <email@hidden>)

  • Prev by Date: Re: Using NSSocketPort
  • Next by Date: Re: What is NSRuleBook and why to I get exceptions ?
  • Previous by thread: Re: NSThread Question
  • Next by thread: Re: My cocoa app don't run on other computers
  • Index(es):
    • Date
    • Thread