Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
In this snippet I am trying to report back to the user via NSProgress.
I am using a concurrent queue to process my work units. The problem occurs when updating the NSProgress instance. The index value is not valid/defined in the concurrent queue. Any idea how to fix this?

Also, are you supposed to manually release objects when obtained with "create_" methods in swift? When I try to release the dispatchGroup, it crashes.

Code:
let privateProgress = NSProgress(totalUnitCount: Int64(_array.count))
		
dispatch_async(self.concurrentQueue) {
	var dispatchGroup	= dispatch_group_create()
	var index : Int64 = 0
			
	//do work concurrently
	for element in _array
	{
		dispatch_semaphore_wait(self.semaphore, DISPATCH_TIME_FOREVER) //start workunit
		dispatch_group_async(dispatchGroup, self.concurrentQueue) {
					
		    //do work with element
		    //...
					
		    //finished
	 	    privateProgress.completedUnitCount = index++ [B]//doesn't work in a concurrent queue[/B]
		    dispatch_semaphore_signal(self.semaphore) //workunit is finished
		}
	}
		
	dispatch_group_wait(dispatchGroup, DISPATCH_TIME_FOREVER);
	//dispatch_release(dispatchGroup) //crash?
			
	//do more work			
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.