I've got an odd crash I'm trying to debug, and some help would be most appreciated.
My main thread crashes like so:
Thread : Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x3316ddfc __pthread_kill + 8
1 libsystem_pthread.dylib 0x331ebd37 pthread_kill + 62
2 libsystem_c.dylib 0x3310d909 abort + 76
3 libc++abi.dylib 0x324389c9 __cxa_bad_cast
4 libc++abi.dylib 0x3244fe29 std::__terminate(void (*)()) + 148
5 libc++abi.dylib 0x3244f8af __cxa_rethrow + 102
6 libobjc.A.dylib 0x32b27dd3 objc_exception_rethrow + 42
7 CoreFoundation 0x2522245d CFRunLoopRunSpecific + 632
8 CoreFoundation 0x252221d3 CFRunLoopRunInMode + 106
9 GraphicsServices 0x2c5da0a9 GSEventRunModal + 136
10 UIKit 0x28831fa1 UIApplicationMain + 1440
11 LifeLock Wallet 0x000e98b1 main (main.mm:21)
The other threads looked alright, until I saw this background thread, where I'm generating 2048-bit RSA keys:
Thread : RSA Key Gen Queue
0 libsystem_kernel.dylib 0x3315c064 fsync + 8
1 MyApp 0x00c697f5 unixSync (sqlite3.c:30624)
2 MyApp 0x00c310f5 syncJournal (sqlite3.c:19113)
3 MyApp 0x00c10d47 sqlite3PagerCommitPhaseOne (sqlite3.c:49218)
4 MyApp 0x00c1101d sqlite3BtreeCommitPhaseOne (sqlite3.c:56943)
5 MyApp 0x00c63107 sqlite3VdbeHalt (sqlite3.c:66150)
6 MyApp 0x00c62bd1 sqlite3VdbeExec (sqlite3.c:70841)
7 MyApp 0x00c11f33 sqlite3_step (sqlite3.c:68643)
8 MyApp 0x00c0cfdf sqlite3_exec (sqlite3.c:98380)
9 MyApp 0x000ee3eb +[DBHelper execStringNormal:] (DBHelper.m:88)
10 MyApp 0x000f448b +[DBHelper insertCategories] (DBHelper.m:1373)
11 MyApp 0x000f34ed +[DBHelper createDB] (DBHelper.m:1147)
12 MyApp 0x000ee97b +[DBHelper initSqlite] (DBHelper.m:212)
13 MyApp 0x000ea245 -[MyApp databaseSetup (MyAppDelegate.m:187)
14 MyApp 0x001fcc69 __37-[Security generateRSAKeyPair]_block_invoke (Security.m:317)
15 libdispatch.dylib 0x330877bb _dispatch_call_block_and_release + 10
16 libdispatch.dylib 0x3308f5b1 _dispatch_queue_drain + 952
17 libdispatch.dylib 0x33089f85 _dispatch_queue_invoke + 84
18 libdispatch.dylib 0x33090b9b _dispatch_root_queue_drain + 338
19 libdispatch.dylib 0x33091cd7 _dispatch_worker_thread3 + 94
20 libsystem_pthread.dylib 0x331e8e31 _pthread_wqthread + 668
This caught my eye because of the general flow in my code. In a nutshell:
- A GCD background thread is created on app start, to generate my RSA keys.
- The class that creates the RSA keys has a protocol to call back to a delegate (in this case, my app delegate), when the keys are ready.
- On the same GCD background thread, I call back to my delegate object.
- Once my app delegate gets called back, I open my SQLite connection and write to the local DB.
My questions are:
- Would writing to the SQLite DB on a background thread cause my 'pthread_kill' crash?
- Is it worth serializing my SQLite DB to ensure that, in the event I have other threads writing to SQLite, I stay thread-safe?
Thanks!
Aucun commentaire:
Enregistrer un commentaire