Re: NSOperationQueue and for-loop

2012-10-03 Thread Mike Abdullah
On 3 Oct 2012, at 14:17, Koen van der Drift wrote: > On Wed, Oct 3, 2012 at 9:03 AM, Koen van der Drift > wrote: > Good point, thanks. So are there any workarounds for that? I'm sure >> this pattern (doing lots of calculations concurrently, and store the >> results in a common object for later)

Re: NSOperationQueue and for-loop

2012-10-03 Thread Koen van der Drift
On Wed, Oct 3, 2012 at 9:03 AM, Koen van der Drift wrote: Good point, thanks. So are there any workarounds for that? I'm sure > this pattern (doing lots of calculations concurrently, and store the > results in a common object for later), is used in other situations as > well. >From a quick search

Re: NSOperationQueue and for-loop

2012-10-03 Thread Koen van der Drift
On Wed, Oct 3, 2012 at 8:48 AM, Mike Abdullah wrote: > Regardless, your posted code is going to blow up sooner or later. NSMutableArray is not safe to modify from more than a single thread at a time. If two of your worker blocks happen to finish at the same time and call -addObject: together, nast

Re: NSOperationQueue and for-loop

2012-10-03 Thread Mike Abdullah
On 3 Oct 2012, at 13:37, Koen van der Drift wrote: > On Tue, Oct 2, 2012 at 10:30 PM, Koen van der Drift > wrote: > >>> Thanks, I'll Google for some examples. For now, I still get an >>> EXC_BAD_ACCESS (code=13, address = 0x0) error in one of the threads after >>> several iterations. Some mo

Re: NSOperationQueue and for-loop

2012-10-03 Thread Koen van der Drift
On Tue, Oct 2, 2012 at 10:30 PM, Koen van der Drift wrote: >> Thanks, I'll Google for some examples. For now, I still get an >> EXC_BAD_ACCESS (code=13, address = 0x0) error in one of the threads after >> several iterations. Some more digging reveals:*** -[MyObject setPosition:]: >> message se

Re: NSOperationQueue and for-loop

2012-10-02 Thread Koen van der Drift
On Oct 2, 2012, at 9:21 PM, davel...@mac.com wrote: > Only variables that are being modified by the block need to be declared with > the __block specifier. You shouldn't be declaring the underlying instance > variables as __block. You can mix and match ARC and non-ARC code. Google > should hel

Re: NSOperationQueue and for-loop

2012-10-02 Thread davelist
On Oct 2, 2012, at 8:43 PM, Koen van der Drift wrote: > > On Oct 2, 2012, at 6:19 PM, Koen van der Drift > wrote: > >> >> On Oct 2, 2012, at 6:07 PM, davel...@mac.com wrote: >> >>> I can't speak to the other examples since I haven't seen them, but the >>> __block specifier is necessary i

Re: NSOperationQueue and for-loop

2012-10-02 Thread Koen van der Drift
On Oct 2, 2012, at 6:19 PM, Koen van der Drift wrote: > > On Oct 2, 2012, at 6:07 PM, davel...@mac.com wrote: > >> I can't speak to the other examples since I haven't seen them, but the >> __block specifier is necessary if your block modifies the variable (your >> block does modify i). Your

Re: NSOperationQueue and for-loop

2012-10-02 Thread Koen van der Drift
On Oct 2, 2012, at 6:07 PM, davel...@mac.com wrote: > I can't speak to the other examples since I haven't seen them, but the > __block specifier is necessary if your block modifies the variable (your > block does modify i). Your example also seems a bit strange since your for > loop modifies i

Re: NSOperationQueue and for-loop

2012-10-02 Thread davelist
On Oct 2, 2012, at 5:49 PM, Koen van der Drift wrote: > Hi, > > When looking how to implement an NSOperationQueue with a loop, I found > several examples that have the following structure: > > NSInteger i; > >for ( i = 0; i < 1000; i++ ) { >[queue addOpera

NSOperationQueue and for-loop

2012-10-02 Thread Koen van der Drift
Hi, When looking how to implement an NSOperationQueue with a loop, I found several examples that have the following structure: NSInteger i; for ( i = 0; i < 1000; i++ ) { [queue addOperationWithBlock:^{ i += 1; }];