Re: NSThread Question
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.