4

I am writing an image uploader which indexes the camera roll on certain events, creates jobs, and then writes those jobs into CoreData. Another thread reads from CoreData to upload the images.

I keep getting UI freezes. Event though the GUI is frozen, I can see that the background queues are continuing to do their jobs. When I break (hit the pause button), I see that the main thread usually looks like this

#0  0x38773ad4 in semaphore_wait_trap ()
#1  0x387e6b10 in _os_semaphore_wait ()
#2  0x386bf76a in _dispatch_barrier_sync_f_slow ()
#3  0x2dc50992 in -[NSManagedObjectContext performBlockAndWait:] ()
#4  0x2d5cb37e in -[ALAssetsLibrary _performBlockAndWait:] ()
#5  0x2d5d06d4 in -[ALAssetPrivate _performBlockAndWait:] ()
#6  0x2d5c4e52 in -[ALAsset defaultRepresentation] ()
#7 my code.... various methods that ar using the asset library

I've scoured the usual forums but cant' seem to find much information on queues and ALAssetsLibrary.

Let me talk about my code some more. As they images are indexed (using _processingQueue) and written into core data, I have a few blocks which (using the main queue) pass data out to the view controller, such as # indexed, # skipped, etc.... Since they are cast into the main queue, I don't see a problem.

As the images are plucked form CoreData and uploaded, there are similar methods which move the upload progress bar, etc.... again cast to the main queue.

What do you think the issue could be here? My methods that access the ALAssetsLibrary are nexted in a @synchonized(self) block. This is all in one class.

Is it wrong to access the library from more than one queue?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
VaporwareWolf
  • 10,143
  • 10
  • 54
  • 80
  • I've realized that it's when a write occurs to the ALAssetsLibrary that is will freeze. Sometimes but not always. Any ideas? – VaporwareWolf Nov 04 '13 at 23:22
  • This looks like a dead lock. Suppose, `[ALAssetsLibrary _performBlockAndWait:]` executes on the main thread. Then, `[NSManagedObjectContext performBlockAndWait:]` will be invoked, and suppose this executes on the main thread, too. What will happen? You may try to alleviate the problem, by either invoking `performBlock:` (and No Wait), or use a private execution context for the managed object context. – CouchDeveloper Nov 04 '13 at 23:46

0 Answers0