4

According to App shutdown with EXC_RESOURCE, WAKEUPS exception on iOS 8 GM and How do I wake up a sleeping pthread, I write two threads, one to wake up the other:

static void *thread1(void *)
{
    struct timeval now;
    struct timezone tz;

    static int64_t count = 0;
    while (gRun) {
        pthread_mutex_lock(&mutex);

        pthread_cond_wait(&cond, &mutex);

        gettimeofday(&now, &tz);
        printf("thread1 wakes up %lld times at %ld:%d\n", count++, now.tv_sec, now.tv_usec);

        pthread_mutex_unlock(&mutex);
    }

    return NULL;
}

static void *thread2(void *)
{
    struct timeval now;
    struct timezone tz;

    static int64_t count = 0;
    while (gRun) {
        pthread_mutex_lock(&mutex);

        pthread_cond_signal(&cond);

        gettimeofday(&now, &tz);
        printf("thread2 wakes up %lld times at %ld:%d\n", count++, now.tv_sec, now.tv_usec);

        pthread_mutex_unlock(&mutex);

        struct timespec a;

        a.tv_sec  = 0;
        a.tv_nsec = 100;

        nanosleep( &a, NULL );
    }

    return NULL;
}

When I create the two threads:

    pthread_mutex_init(&mutex, NULL);
    pthread_cond_init(&cond, NULL);

    pthread_t tid;
    pthread_create(&tid, NULL, thread1, NULL);
    pthread_create(&tid, NULL, thread2, NULL);

The console will print wakeup times at us:ns format time, so I can count how many times one thread wakes up -- more than 1000, but the application only crashed once:

Date/Time:           2014-10-25 16:12:01.187 +0800
Launch Time:         2014-10-25 16:11:54.118 +0800
OS Version:          iOS 8.0.2 (12A405)
Report Version:      105

Exception Type:  EXC_RESOURCE
Exception Subtype: WAKEUPS
Exception Message: (Limit 150/sec) Observed 6418/sec over 300 secs
Triggered by Thread:  6

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib          0x33580518 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3358030c mach_msg + 36
2   CoreFoundation                  0x25799dc6 __CFRunLoopServiceMachPort + 142
3   CoreFoundation                  0x2579838c __CFRunLoopRun + 1012
4   CoreFoundation                  0x256e5dac CFRunLoopRunSpecific + 472
5   CoreFoundation                  0x256e5bbe CFRunLoopRunInMode + 102
6   GraphicsServices                0x2ca7104c GSEventRunModal + 132
7   UIKit                           0x28cb1a2c UIApplicationMain + 1436
8   EXC_RESOURCE_DEMO               0x00032df4 0x2c000 + 28148
9   libdyld.dylib                   0x334ceaac start + 0

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x335802c8 kevent64 + 24
1   libdispatch.dylib               0x334a2ec4 _dispatch_mgr_invoke + 276
2   libdispatch.dylib               0x334a2bf6 _dispatch_mgr_thread$VARIANT$mp + 34

Thread 2:
0   libsystem_kernel.dylib          0x335949cc __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x33610e9c _pthread_wqthread + 788
2   libsystem_pthread.dylib         0x33610b74 start_wqthread + 4

Thread 3:
0   libsystem_kernel.dylib          0x335949cc __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x33610e9c _pthread_wqthread + 788
2   libsystem_pthread.dylib         0x33610b74 start_wqthread + 4

Thread 4:
0   libsystem_kernel.dylib          0x335949cc __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x33610e9c _pthread_wqthread + 788
2   libsystem_pthread.dylib         0x33610b74 start_wqthread + 4

Thread 5:
0   libsystem_kernel.dylib          0x335949cc __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x33610e9c _pthread_wqthread + 788
2   libsystem_pthread.dylib         0x33610b74 start_wqthread + 4

Thread 6 Attributed:
0   libsystem_kernel.dylib          0x33593b38 0x3357f000 + 84792
1   libsystem_pthread.dylib         0x336123dc 0x33610000 + 9180
2   libsystem_pthread.dylib         0x336132ac 0x33610000 + 12972
3   EXC_RESOURCE_DEMO               0x000328f8 0x2c000 + 26872
4   libsystem_pthread.dylib         0x33612e64 _pthread_body + 136
5   libsystem_pthread.dylib         0x33612dd6 _pthread_start + 114
6   libsystem_pthread.dylib         0x33610b80 thread_start + 4

So, my question is, with so many wakeups per second, about 6000/sec, why the app only crashed once? How can I make it always crashed due to EXC_RESOURCE / WAKEUPS?

Thanks!

Community
  • 1
  • 1
Jason Lee
  • 3,200
  • 1
  • 34
  • 71

1 Answers1

0

Have you solved it ? I face same problem;

I think wakeups Exception is not the real reason of the crash; because I write a demo to repear this crash like you, when the demo runing, I exit the demo by myself, this log also be generated, also Exception Subtype: WAKEUPS, so I think it is some other reason due to this, may be memory is too high;

codeWorm
  • 1
  • 1