Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug syscall_thread_switch in iOS 8.3?

Since moving to iOS 8.3, I'm encountering this error where the main thread will get stuck in this call. A few other threads are also stuck in that call. There is none of my code in any thread that leads to this call, so I'm stumped as to why this is happening. It happens randomly, sometimes, when tapping a button bar item, sometimes while redrawing charts (using ShinobiCharts), etc.

Here is the stack trace from Xcode:

enter image description here

Anybody has any clue as to why this is happening and how to fix it? It's very annoying because when I get stuck there, I have to relaunch the app. Note that this is happening in the simulator so far. I'm in the early stage of developing this app and spend most of my time in the simulator. I haven't seen the error happening yet on a real device but, again, I haven't run the app that often on the device.

like image 259
nemesys Avatar asked May 06 '15 16:05

nemesys


1 Answers

Knock on wood, but I think I figured it out (at least in my instance).

What led to the solution was a search for syscall_thread_switch, which led me to this answer here: https://stackoverflow.com/a/30333203/978509

Which, if you look at the backtrace I linked (https://gist.github.com/Shalmezad/65ff89d20aa7e0a9d094), every syscall_thread_switch is preceded by OSSpinLockLockSlow, which the answer notes looks like Livelock, but due to the low CPU usage, is more evident of a deadlock.

Going through my code, I found that for every background task, I created a new dispatch_queue_t each time. I since redid how that works to use the same queue, which seems to have fixed the issue.

Without further information from nemesis (mainly some code snippets showing how he's setting up background tasks), I cannot answer their specific question, however this should point people in the right direction for fixing the issue.

like image 131
Shalmezad Avatar answered Nov 20 '22 16:11

Shalmezad