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.
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
}