last day (15 days later) » 

6:54 PM
2
Q: Concurrent threads not running concurrently after Archive and Export

Mackey18When running my OSX application through Xcode, my threads work absolutely fine, however, when I archive the application and Export as a Mac Application the app quite clearly jams on the main thread in exactly the place where the concurrent thread was working. Any ideas? Some of my code is attac...

 
Have you checked the dispatch queue the completion handler i executing onto, in both situations (xcode and exported)?
 
@Cristik yep, runs correctly in Xcode not checked on the app
@Cristik managed to finally getting around to looking at this again, been busy. I can confirm that the archived application is running purely on Thread 1 and not on an alternative thread. I just can't understand why.
 
Can you provide the code for getLiveMatches? Maybe there's something there that causes the unexpected behaviour.
 
@Cristik Added to question. I'm beginning to think this is an issue with Alamofire as that manages all the queues
 
Looking at the Alamofire code, there are 3 possibilities why the code ends up on the main thread: - dispatch_queue_create return the main queue - dispatch_queue_create returns nil - the dispatch_async used by Alamofire schedules the block on the main thread. It should be easy to check the first and second one by printing the result queue.
 
6:54 PM
@Cristik and how would I do this for the archived application? It obviously will show it's working if the project is run through Xcode. As a side note, I just updated the Alamofire submodule.
 
You can print the queue information and look at the console log to see what the app says
 
@Cristik Okay give me a few
@Cristik okay, looking at the debugDescriptions of both the main queue and the concurrent queue, the memory references suggest that they are not the same, nor is the queue created nil. Further, by using the queue flags, I confirmed that the block in the request is not running on the main queue, by using (dispatch_queue_get_label(dispatch_get_main_queue()) == dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)). It seems then that the concurrent queue is being placed onto the main thread.
A further development. I'm able to recreate the issue in the Xcode version when I call the reloadTableView() function a second time.
 
7:19 PM
This is now definitely down Alamofire's end. If I call the same network call twice it'll put the second one on the main thread, however, if I do an unrelated network call (without a specified queue) in between, then the error won't arise.
 
8:04 PM
I remember a discussion at a certain time in the past about GCD executing the blocks on the main thread, even if a custom queue was used to enqueue the block, because the main thread was free when the block was submitted. Perhaps this is what is happening to you too
 
Literally just figured this out this second. It's essentially that but in reverse. Because I was using async on the main queue I think it was being put in parallel with the concurrent queue (so they're executing freely at the same time) when the main thread wasn't free. And this completely negated the effect of having the separate parts of the code on different queues, as they were being treated the same as asynchronous blocs.
Wait that doesn't make sense. Maybe the async dispatch of the main queue made GCD go crazy and not knowing what to do, put everything on the main thread
Whatever it was, setting the dispatch to sync on the main thread solved it
Thanks for all the help, I really appreciate it.
 

last day (15 days later) »