0

My apps UI stucks because of semaphore_wait_trap. I don't know how to track it. I've checked if I am updating any UI from background thread. But did not find any. Here is the stack trace.

enter image description here

Any help will be appreciated.

Here is the thread backtrace result:

    warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
* thread #1: tid = 0x57d93, 0x3814800c libsystem_kernel.dylib`semaphore_wait_trap + 8, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x3814800c libsystem_kernel.dylib`semaphore_wait_trap + 8
    frame #1: 0x381f5288 libsystem_platform.dylib`_os_semaphore_wait + 12
    frame #2: 0x008f0178 libdispatch.dylib`_dispatch_barrier_sync_f_slow + 412
    frame #3: 0x0045318a IssMan - Construction punchlist, on-site inspection and snagging`NR__dispatch_sync(queue=0x1667fc50, block=<unavailable>) + 126 at NRGCDOverride.m:89 [opt]
    frame #4: 0x00366116 IssMan - Construction punchlist, on-site inspection and snagging`-[FMDatabaseQueue inDatabase:](self=0x166459f0, _cmd="inDatabase:", block=(IssMan - Construction punchlist, on-site inspection and snagging`__29+[UserDAO getLanguageOfUser:]_block_invoke + 1 at UserDAO.m:445)) + 230 at FMDatabaseQueue.m:151
    frame #5: 0x0038105e IssMan - Construction punchlist, on-site inspection and snagging`+[UserDAO getLanguageOfUser:](self=0x0057d34c, _cmd="getLanguageOfUser:", user=0x16703460) + 298 at UserDAO.m:445
    frame #6: 0x0010288a IssMan - Construction punchlist, on-site inspection and snagging`-[MenuViewController setLanguage](self=0x1717ba00, _cmd="setLanguage") + 226 at MenuViewController.m:316
    frame #7: 0x001038e4 IssMan - Construction punchlist, on-site inspection and snagging`-[MenuViewController viewWillAppear:](self=0x1717ba00, _cmd="viewWillAppear:", animated=YES) + 420 at MenuViewController.m:420
    frame #8: 0x0044ecfa IssMan - Construction punchlist, on-site inspection and snagging`NRMA__boolParamHandler(self=0x1717ba00, selector="viewWillAppear:", targetColor=<unavailable>, p1=<unavailable>) + 42 at NRMAMethodProfiler.m:770 [opt]
    frame #9: 0x2a3ca018 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 572
    frame #10: 0x2a3c9dba UIKit`-[UIViewController __viewWillAppear:] + 146
    frame #11: 0x2a55f340 UIKit`-[UINavigationController _startCustomTransition:] + 1052
    frame #12: 0x2a46da6e UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 650
    frame #13: 0x2a46d77c UIKit`-[UINavigationController __viewWillLayoutSubviews] + 52
    frame #14: 0x2a46d6f6 UIKit`-[UILayoutContainerView layoutSubviews] + 214
    frame #15: 0x2a3adcc2 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 694
    frame #16: 0x29c75b04 QuartzCore`-[CALayer layoutSublayers] + 128
    frame #17: 0x29c71200 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 352
    frame #18: 0x29c71090 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
    frame #19: 0x29c705b0 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 368
    frame #20: 0x29c70262 QuartzCore`CA::Transaction::commit() + 614
    frame #21: 0x29c69a1e QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 138
    frame #22: 0x26240090 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
    frame #23: 0x2623e386 CoreFoundation`__CFRunLoopDoObservers + 282
    frame #24: 0x2623e7c4 CoreFoundation`__CFRunLoopRun + 972
    frame #25: 0x261910d8 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #26: 0x26190ecc CoreFoundation`CFRunLoopRunInMode + 108
    frame #27: 0x2f506af8 GraphicsServices`GSEventRunModal + 160
    frame #28: 0x2a41a2dc UIKit`UIApplicationMain + 144
    frame #29: 0x000d0872 IssMan - Construction punchlist, on-site inspection and snagging`main(argc=1, argv=0x008c5a78) + 102 at main.m:17

  thread #4: tid = 0x57db4, 0x3815d320 libsystem_kernel.dylib`kevent_qos + 24, queue = 'com.apple.libdispatch-manager'
    frame #0: 0x3815d320 libsystem_kernel.dylib`kevent_qos + 24
    frame #1: 0x008f75f6 libdispatch.dylib`_dispatch_mgr_invoke + 254
    frame #2: 0x008e89ce libdispatch.dylib`_dispatch_mgr_thread + 38

  thread #5: tid = 0x57db7, 0x3814800c libsystem_kernel.dylib`semaphore_wait_trap + 8, queue = 'harvesterQueue'
    frame #0: 0x3814800c libsystem_kernel.dylib`semaphore_wait_trap + 8
    frame #1: 0x008f54ba libdispatch.dylib`_dispatch_semaphore_wait_slow + 190
    frame #2: 0x25ae3cdc CFNetwork`CFURLConnectionSendSynchronousRequest + 272
    frame #3: 0x25afe2fe CFNetwork`+[NSURLConnection sendSynchronousRequest:returningResponse:error:] + 94
    frame #4: 0x004387ba IssMan - Construction punchlist, on-site inspection and snagging`__65+[NRMANSURLConnectionSupport poseImplementationBlockForSelector:]_block_invoke(.block_descriptor=<unavailable>, _self=<unavailable>, request=0x1657a3f0, response=0x401969dc, error=<unavailable>) + 146 at NRMANSURLConnectionSupport.m:204 [opt]
    frame #5: 0x00442faa IssMan - Construction punchlist, on-site inspection and snagging`-[NRMAHarvesterConnection send:](self=<unavailable>, _cmd=<unavailable>, post=<unavailable>) + 130 at NRMAHarvesterConnection.m:97 [opt]
    frame #6: 0x00443808 IssMan - Construction punchlist, on-site inspection and snagging`-[NRMAHarvesterConnection sendData:](self=0x165574c0, _cmd=<unavailable>, harvestable=<unavailable>) + 416 at NRMAHarvesterConnection.m:160 [opt]
    frame #7: 0x0043c784 IssMan - Construction punchlist, on-site inspection and snagging`-[NRMAHarvester connected](self=<unavailable>, _cmd=<unavailable>) + 724 at NRMAHarvester.m:268 [opt]
    frame #8: 0x0043e23a IssMan - Construction punchlist, on-site inspection and snagging`-[NRMAHarvester execute](self=<unavailable>, _cmd=<unavailable>) + 522 at NRMAHarvester.m:505 [opt]
    frame #9: 0x0043cf4c IssMan - Construction punchlist, on-site inspection and snagging`-[NRMAHarvester disconnected](self=<unavailable>, _cmd=<unavailable>) + 276 at NRMAHarvester.m:350 [opt]
    frame #10: 0x0043e1f6 IssMan - Construction punchlist, on-site inspection and snagging`-[NRMAHarvester execute](self=<unavailable>, _cmd=<unavailable>) + 454 at NRMAHarvester.m:500 [opt]
    frame #11: 0x004471f4 IssMan - Construction punchlist, on-site inspection and snagging`__30+[NRMAHarvestController start]_block_invoke_2(.block_descriptor=<unavailable>) + 412 at NRMAHarvestController.m:143 [opt]
    frame #12: 0x008e6d16 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #13: 0x008f161a libdispatch.dylib`_dispatch_queue_drain + 2014
    frame #14: 0x008e9f52 libdispatch.dylib`_dispatch_queue_invoke + 282
    frame #15: 0x008f306e libdispatch.dylib`_dispatch_root_queue_drain + 1802
    frame #16: 0x008f2960 libdispatch.dylib`_dispatch_worker_thread3 + 100
    frame #17: 0x381f8e0c libsystem_pthread.dylib`_pthread_wqthread + 1024
    frame #18: 0x381f89fc libsystem_pthread.dylib`start_wqthread + 8

  thread #6: tid = 0x57dba, 0x3815bf14 libsystem_kernel.dylib`__select + 20, name = 'com.apple.CFSocket.private'
    frame #0: 0x3815bf14 libsystem_kernel.dylib`__select + 20
    frame #1: 0x26245930 CoreFoundation`__CFSocketManager + 572
    frame #2: 0x381fac7e libsystem_pthread.dylib`_pthread_body + 138
    frame #3: 0x381fabf2 libsystem_pthread.dylib`_pthread_start + 110
    frame #4: 0x381f8a08 libsystem_pthread.dylib`thread_start + 8

  thread #7: tid = 0x57dc4, 0x38147fbc libsystem_kernel.dylib`mach_msg_trap + 20, name = 'com.apple.NSURLConnectionLoader'
    frame #0: 0x38147fbc libsystem_kernel.dylib`mach_msg_trap + 20
    frame #1: 0x38147dbc libsystem_kernel.dylib`mach_msg + 40
    frame #2: 0x2624048c CoreFoundation`__CFRunLoopServiceMachPort + 136
    frame #3: 0x2623e812 CoreFoundation`__CFRunLoopRun + 1050
    frame #4: 0x261910d8 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #5: 0x26190ecc CoreFoundation`CFRunLoopRunInMode + 108
    frame #6: 0x25afdd9e CFNetwork`+[NSURLConnection(Loader) _resourceLoadLoop:] + 486
    frame #7: 0x2705436c Foundation`__NSThread__start__ + 1144
    frame #8: 0x381fac7e libsystem_pthread.dylib`_pthread_body + 138
    frame #9: 0x381fabf2 libsystem_pthread.dylib`_pthread_start + 110
    frame #10: 0x381f8a08 libsystem_pthread.dylib`thread_start + 8

  thread #8: tid = 0x57dc8, 0x3815c88c libsystem_kernel.dylib`__workq_kernreturn + 8
    frame #0: 0x3815c88c libsystem_kernel.dylib`__workq_kernreturn + 8
    frame #1: 0x381f8e18 libsystem_pthread.dylib`_pthread_wqthread + 1036
    frame #2: 0x381f89fc libsystem_pthread.dylib`start_wqthread + 8

  thread #10: tid = 0x57dca, 0x3815c024 libsystem_kernel.dylib`__semwait_signal + 24, queue = 'NSOperationQueue 0x165eafe0 :: NSOperation 0x16782190 (QOS: USER_INTERACTIVE)'
    frame #0: 0x3815c024 libsystem_kernel.dylib`__semwait_signal + 24
    frame #1: 0x380b391c libsystem_c.dylib`nanosleep + 172
    frame #2: 0x27053856 Foundation`+[NSThread sleepForTimeInterval:] + 142
    frame #3: 0x002e1d24 IssMan - Construction punchlist, on-site inspection and snagging`-[MetaDataSyncOperation main](self=0x16782190, _cmd="main") + 368 at MetaDataSyncOperation.m:48
    frame #4: 0x26f903ce Foundation`-[__NSOperationInternal _start:] + 774
    frame #5: 0x2703e82c Foundation`__NSOQSchedule_f + 192
    frame #6: 0x008f161a libdispatch.dylib`_dispatch_queue_drain + 2014
    frame #7: 0x008e9f52 libdispatch.dylib`_dispatch_queue_invoke + 282
    frame #8: 0x008f2b0e libdispatch.dylib`_dispatch_root_queue_drain + 426
    frame #9: 0x008f2960 libdispatch.dylib`_dispatch_worker_thread3 + 100
    frame #10: 0x381f8e0c libsystem_pthread.dylib`_pthread_wqthread + 1024
    frame #11: 0x381f89fc libsystem_pthread.dylib`start_wqthread + 8

  thread #11: tid = 0x57dcd, 0x38147fbc libsystem_kernel.dylib`mach_msg_trap + 20, name = 'AFNetworking'
    frame #0: 0x38147fbc libsystem_kernel.dylib`mach_msg_trap + 20
    frame #1: 0x38147dbc libsystem_kernel.dylib`mach_msg + 40
    frame #2: 0x2624048c CoreFoundation`__CFRunLoopServiceMachPort + 136
    frame #3: 0x2623e812 CoreFoundation`__CFRunLoopRun + 1050
    frame #4: 0x261910d8 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #5: 0x26190ecc CoreFoundation`CFRunLoopRunInMode + 108
    frame #6: 0x26f8388c Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 268
    frame #7: 0x26fd241c Foundation`-[NSRunLoop(NSRunLoop) run] + 80
    frame #8: 0x003e306e IssMan - Construction punchlist, on-site inspection and snagging`+[AFURLConnectionOperation networkRequestThreadEntryPoint:](self=0x0057d914, _cmd="networkRequestThreadEntryPoint:", object=0x00000000) + 354 at AFURLConnectionOperation.m:163
    frame #9: 0x2705436c Foundation`__NSThread__start__ + 1144
    frame #10: 0x381fac7e libsystem_pthread.dylib`_pthread_body + 138
    frame #11: 0x381fabf2 libsystem_pthread.dylib`_pthread_start + 110
    frame #12: 0x381f8a08 libsystem_pthread.dylib`thread_start + 8

  thread #12: tid = 0x57dce, 0x38148dc0 libsystem_kernel.dylib`pread + 20, queue = 'fmdb.<FMDatabaseQueue: 0x166459f0>'
    frame #0: 0x38148dc0 libsystem_kernel.dylib`pread + 20
    frame #1: 0x37e41252 libsqlite3.dylib`___lldb_unnamed_function356$$libsqlite3.dylib + 206
    frame #2: 0x37ddded0 libsqlite3.dylib`___lldb_unnamed_function25$$libsqlite3.dylib + 24
    frame #3: 0x37df6824 libsqlite3.dylib`___lldb_unnamed_function77$$libsqlite3.dylib + 120
    frame #4: 0x37df5bb6 libsqlite3.dylib`___lldb_unnamed_function72$$libsqlite3.dylib + 718
    frame #5: 0x37e47f7a libsqlite3.dylib`___lldb_unnamed_function431$$libsqlite3.dylib + 250
    frame #6: 0x37e2ef5a libsqlite3.dylib`___lldb_unnamed_function250$$libsqlite3.dylib + 718
    frame #7: 0x37e3bffe libsqlite3.dylib`___lldb_unnamed_function316$$libsqlite3.dylib + 234
    frame #8: 0x37e186b6 libsqlite3.dylib`___lldb_unnamed_function159$$libsqlite3.dylib + 158
    frame #9: 0x37e0c4b0 libsqlite3.dylib`___lldb_unnamed_function114$$libsqlite3.dylib + 24192
    frame #10: 0x37e05b48 libsqlite3.dylib`sqlite3_step + 472
    frame #11: 0x00280fe0 IssMan - Construction punchlist, on-site inspection and snagging`-[FMResultSet nextWithError:](self=0x17a2d5b0, _cmd="nextWithError:", outErr=0x00000000) + 64 at FMResultSet.m:155
    frame #12: 0x00280f9a IssMan - Construction punchlist, on-site inspection and snagging`-[FMResultSet next](self=0x17a2d5b0, _cmd="next") + 42 at FMResultSet.m:150
    frame #13: 0x001001da IssMan - Construction punchlist, on-site inspection and snagging`__45-[SyncStatusCalculatorOperation updateStatus]_block_invoke101(.block_descriptor=0x40524bcc, db=0x1667e750) + 198 at SyncStatusCalculatorOperation.m:152
    frame #14: 0x00366194 IssMan - Construction punchlist, on-site inspection and snagging`__30-[FMDatabaseQueue inDatabase:]_block_invoke(.block_descriptor=0x40524a54) + 88 at FMDatabaseQueue.m:151
    frame #15: 0x004531c6 IssMan - Construction punchlist, on-site inspection and snagging`__NR__dispatch_sync_block_invoke(.block_descriptor=<unavailable>) + 30 at NRGCDOverride.m:91 [opt]
    frame #16: 0x008e6d02 libdispatch.dylib`_dispatch_client_callout + 22
    frame #17: 0x008f04fa libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 102
    frame #18: 0x0045318a IssMan - Construction punchlist, on-site inspection and snagging`NR__dispatch_sync(queue=0x1667fc50, block=<unavailable>) + 126 at NRGCDOverride.m:89 [opt]
    frame #19: 0x00366116 IssMan - Construction punchlist, on-site inspection and snagging`-[FMDatabaseQueue inDatabase:](self=0x166459f0, _cmd="inDatabase:", block=(IssMan - Construction punchlist, on-site inspection and snagging`__45-[SyncStatusCalculatorOperation updateStatus]_block_invoke101 + 1 at SyncStatusCalculatorOperation.m:140)) + 230 at FMDatabaseQueue.m:151
    frame #20: 0x000ff3e4 IssMan - Construction punchlist, on-site inspection and snagging`-[SyncStatusCalculatorOperation updateStatus](self=0x178ed200, _cmd="updateStatus") + 1884 at SyncStatusCalculatorOperation.m:140
    frame #21: 0x000fec7a IssMan - Construction punchlist, on-site inspection and snagging`-[SyncStatusCalculatorOperation main](self=0x178ed200, _cmd="main") + 290 at SyncStatusCalculatorOperation.m:35
    frame #22: 0x26f903ce Foundation`-[__NSOperationInternal _start:] + 774
    frame #23: 0x2703e82c Foundation`__NSOQSchedule_f + 192
    frame #24: 0x008f161a libdispatch.dylib`_dispatch_queue_drain + 2014
    frame #25: 0x008e9f52 libdispatch.dylib`_dispatch_queue_invoke + 282
    frame #26: 0x008f2b0e libdispatch.dylib`_dispatch_root_queue_drain + 426
    frame #27: 0x008f2960 libdispatch.dylib`_dispatch_worker_thread3 + 100
    frame #28: 0x381f8e0c libsystem_pthread.dylib`_pthread_wqthread + 1024
    frame #29: 0x381f89fc libsystem_pthread.dylib`start_wqthread + 8

  thread #13: tid = 0x57dd1, 0x38147fbc libsystem_kernel.dylib`mach_msg_trap + 20, name = 'WebThread'
    frame #0: 0x38147fbc libsystem_kernel.dylib`mach_msg_trap + 20
    frame #1: 0x38147dbc libsystem_kernel.dylib`mach_msg + 40
    frame #2: 0x2624048c CoreFoundation`__CFRunLoopServiceMachPort + 136
    frame #3: 0x2623e812 CoreFoundation`__CFRunLoopRun + 1050
    frame #4: 0x261910d8 CoreFoundation`CFRunLoopRunSpecific + 516
    frame #5: 0x26190ecc CoreFoundation`CFRunLoopRunInMode + 108
    frame #6: 0x351868d6 WebCore`RunWebThread(void*) + 422
    frame #7: 0x381fac7e libsystem_pthread.dylib`_pthread_body + 138
    frame #8: 0x381fabf2 libsystem_pthread.dylib`_pthread_start + 110
    frame #9: 0x381f8a08 libsystem_pthread.dylib`thread_start + 8

  thread #15: tid = 0x57e0e, 0x3815c88c libsystem_kernel.dylib`__workq_kernreturn + 8
    frame #0: 0x3815c88c libsystem_kernel.dylib`__workq_kernreturn + 8
    frame #1: 0x381f8e18 libsystem_pthread.dylib`_pthread_wqthread + 1036
    frame #2: 0x381f89fc libsystem_pthread.dylib`start_wqthread + 8

Here is the source of updateStatus:

-(void)updateStatus {

    if(isCalculating)return;

    isCalculating = YES;
    NSMutableArray *tableList = [[NSMutableArray alloc] init];

    [[IssMANAppDelegate appDelegate].dbQueue inDatabase:^(FMDatabase *db) {
        FMResultSet *resultsSet = [db executeQuery:@"SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"];
        while ([resultsSet next]){
            [tableList addObject:[resultsSet stringForColumn:@"name"]];
        }
        [resultsSet close];
    }];

    __block int totalRow = 0;
    __block int pendingRow = 0;
//    totalPhotoRow = 0;
    __block int pendingPhotoRow = 0;
    __block int pendingDataDownload = 0;
    __block int pendingPhotoDownload = 0;

//    __block NSInteger pendingPhotoRow = 0;
    [[IssMANAppDelegate appDelegate].dbQueue inDatabase:^(FMDatabase *db) {
        FMResultSet *resultSet = nil;
        resultSet = [db executeQuery:@"SELECT COUNT(*) C FROM media_content, media WHERE media.pk_id = media_content.media_pk_id AND media.status = 'active' AND media_content.is_dirty = 1"];

        while([resultSet next]){
            pendingPhotoRow = [resultSet intForColumn:@"C"];
        }
        [resultSet close];
    }];

    //    pendingPhotoRow = [MediaDAO getPendingUploadImages];
    for(int k=0;k<tableList.count;k++) {

        NSString* tableName = (NSString*) [tableList objectAtIndex:k];

        if([tableName isEqualToString:@"settings"])continue;
        if([tableName isEqualToString:@"sqlite_sequence"])continue;
        if([tableName isEqualToString:@"temp_purchased_transactions"])continue;
        if([tableName isEqualToString:@"latest_project_report_issue"])continue;
        if([tableName isEqualToString:@"role"])continue;
        if([tableName isEqualToString:@"event_type"])continue;
        if([tableName isEqualToString:@"rel_role_event_type_notification_type"])continue;
        if([tableName isEqualToString:@"rel_user_product"])continue;
        if([tableName isEqualToString:@"media_content"])continue;

        [[IssMANAppDelegate appDelegate].dbQueue inDatabase:^(FMDatabase *db) {
            NSString* sql = NULL;
            if([ISSManDBManager columnExists:@"status" inTableWithName:tableName andDB:db]) {

                sql = [NSString stringWithFormat:@"SELECT COUNT(*) C FROM %@ where status <> 'deleted'",tableName];
            }
            else if([ISSManDBManager columnExists:@"sender_status" inTableWithName:tableName andDB:db]) {

                sql = [NSString stringWithFormat:@"SELECT COUNT(*) C FROM %@ where sender_status <> 'deleted'",tableName];
        }
        else {

            sql = [NSString stringWithFormat:@"SELECT COUNT(*) C FROM %@",tableName];
        }

        FMResultSet *resultSet = [db executeQuery:sql];

        while([resultSet next]) {
            int rowCount = [resultSet intForColumn:@"C"];
            if([tableName isEqualToString:@"media_content"]) {
//                    totalPhotoRow += rowCount;
            }
            else {
                totalRow += rowCount;
            }
        }

        if([ISSManDBManager columnExists:@"status" inTableWithName:tableName andDB:db]) {
            sql = [NSString stringWithFormat:@"SELECT COUNT(*) C FROM %@ WHERE is_dirty = 1 and status <> 'deleted'",tableName];
        }
        else if([ISSManDBManager columnExists:@"sender_status" inTableWithName:tableName andDB:db]) {
            sql = [NSString stringWithFormat:@"SELECT COUNT(*) C FROM %@ WHERE is_dirty = 1 and sender_status <> 'deleted'",tableName];
        }
        else {
            sql = [NSString stringWithFormat:@"SELECT COUNT(*) C FROM %@ WHERE is_dirty = 1",tableName];
        }
        resultSet = [db executeQuery:sql];

        while([resultSet next]) {
            NSInteger rowCount = [resultSet intForColumn:@"C"];
            pendingRow += rowCount;
        }
        [resultSet close];
    }];
}

[[IssMANAppDelegate appDelegate].dbQueue inDatabase:^(FMDatabase *db) {

    NSString* sql = NULL;
    sql = [NSString stringWithFormat:@"SELECT COUNT(media.pk_id) C \
           FROM media, media_content \
           WHERE \
           media.pk_id = media_content.media_pk_id AND \
           media.status = 'active' AND \
           media.update_date_time > media_content.last_sync_time"];

    FMResultSet *resultingSet = [db executeQuery:sql];

    while ([resultingSet next]) {

        int rowCount = [resultingSet intForColumn:@"C"];
        pendingPhotoDownload += rowCount;
    }
    [resultingSet close];

    NSString *sqlQuery = [NSString stringWithFormat:@"SELECT COUNT(pk_id) C FROM rel_user_product"];
    FMResultSet *resultsSets = [db executeQuery:sqlQuery];


    while([resultsSets next]) {

        int rowCount = [resultsSets intForColumn:@"C"];
        pendingDataDownload += rowCount;
    }
    [resultsSets close];
}];

double ratio = 0.0;
if(totalRow)ratio = (double)pendingRow / (double)totalRow * 100.0;

ratio = floor(100.0 - ratio);
double downloadRation = 0.0;
if(pendingDataDownload) downloadRation = 100.0;

isCalculating = NO;

NSMutableDictionary* syncStatusDic = [[NSMutableDictionary alloc] init];
[syncStatusDic setObject:[NSNumber numberWithInt:totalRow] forKey:TOTAL_ROW];
[syncStatusDic setObject:[NSNumber numberWithInt:pendingRow] forKey:PENDING_ROW];
[syncStatusDic setObject:[NSNumber numberWithInt:pendingPhotoRow] forKey:PENDING_PHOTO];
[syncStatusDic setObject:[NSNumber numberWithInt:pendingDataDownload] forKey:PENDING_DATA_DOWNLOAD];
[syncStatusDic setObject:[NSNumber numberWithInt:pendingPhotoDownload] forKey:PENDING_PHOTO_DOWNLOAD];

    [self.delegate updateSyncStatusValues: [NSDictionary dictionaryWithDictionary:syncStatusDic]]; // safe conversion from NSMutableDictionary to NSDictionary
}
Rashad
  • 11,057
  • 4
  • 45
  • 73
  • It's waiting to execute a block on a queue. The queue is locked, so it's probably executing a block on another thread. You need to look at the stack traces of the other threads to see which one is blocking the queue and why. – rob mayoff Nov 24 '15 at 04:24
  • @robmayoff > Sorry if it sounds stupid, how can I understand which one is blocking the queue from other thread? – Rashad Nov 24 '15 at 04:27
  • @robmayoff > I've added another thread queue, which I think might be the reason. Am I correct? Thanks for your time. – Rashad Nov 24 '15 at 04:31
  • In the debugger (at the `(lldb)` prompt), type `thread backtrace all`. Copy the output and paste it into your question. – rob mayoff Nov 24 '15 at 04:56
  • @robmayoff > The result is added. – Rashad Nov 24 '15 at 05:06
  • None of those threads is in `semaphore_wait_trap`. You have to get the app into the “stuck” state, then pause in the debugger and print the thread backtraces. – rob mayoff Nov 24 '15 at 05:11
  • @robmayoff > Sorry my bad. Please see now. – Rashad Nov 24 '15 at 05:18

1 Answers1

1

Thread #12 in your backtrace is running on the database queue, performing -[SyncStatusCalculatorOperation updateStatus] (frame #13). Until that block returns, no other thread can run on the database queue. Your main thread (thread #1) will block until thread #12 gets off of the database queue.

You need to look at -[SyncStatusCalculatorOperation updateStatus] to figure out why it's taking so long.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Can you suggest how to overcome this? I did this part in background thread. Can't determine why this is blocking. I've added the source of that function. On my question. – Rashad Nov 24 '15 at 05:39
  • Find that thread in the debug navigator, and click on the frame just above `-[FMResultSet next]`. Which block of your method is it executing? What's the SQL query? Do you have the appropriate indexes to make that query fast? – rob mayoff Nov 24 '15 at 05:42
  • Yes I have indexes. I've edited my question and added the method. – Rashad Nov 24 '15 at 05:46
  • I saw that you added the message but I don't know which line is line 152. – rob mayoff Nov 24 '15 at 06:18
  • 152 is a blank line, 153 and 154 is these: NSString *sqlQuery = [NSString stringWithFormat:@"SELECT COUNT(pk_id) C FROM rel_user_product"]; FMResultSet *resultsSets = [db executeQuery:sqlQuery]; – Rashad Nov 24 '15 at 06:21