hockeyman
hockeyman

Reputation: 1183

iOS app breaks unexpectedly. Multithreading issue (probably)

I have an app where I read data from input stream and visualize it to user. When I set up input stream, I set it up in background run loop, open it and then run a background loop. But sometimes my app breaks unexpectedly. I can't repeat this crash so I don't even know where to start to fix it.

The crash I get looks like this: enter image description here

And the method where it crashes looks like this: enter image description here

It says that it is Enqueued from background queue (Thread 3). And Thread 3 looks like that: enter image description here

What could be the reason of this? Where should I start to fix it?


And the strange thing is that in Thread 17, where it crashes variable bg_queue is nil, and anyway it passes the if condition where i do

if (bg_queue != nil)

But in Thread 3 it is not nil:

Thread 17 enter image description here

Thread 3 enter image description here

Upvotes: 0

Views: 71

Answers (2)

gnasher729
gnasher729

Reputation: 52546

If you create a second runloop, you are more courageous than I am. I would never dare doing that, because I would be just sure that it leads to problems that are too hard for me to fix. As you are finding out.

If you are sure that you are a much more clever developer than I am, then sorry, you're on your own. If you are not sure, then DON'T DO THAT! Stay away from secondary run loops!

Upvotes: 1

CouchDeveloper
CouchDeveloper

Reputation: 19116

It seems, you create a run loop from a secondary thread managed by GCD. You should not obtain a run loop from a thread that is managed by GCD!

Create your own dedicated thread or use the main thread to obtain a run loop.

Upvotes: 2

Related Questions