gpt4 book ai didi

ios - EXC_RESOURCE 崩溃并不总是显示在 iOS 8 上,有很多线程唤醒?

转载 作者:可可西里 更新时间:2023-11-01 06:14:48 25 4
gpt4 key购买 nike

根据 App shutdown with EXC_RESOURCE, WAKEUPS exception on iOS 8 GMHow do I wake up a sleeping pthread ,我写了两个线程,一个唤醒另一个:

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;
}

当我创建两个线程时:

    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);

控制台将以 us:ns 格式时间打印唤醒时间,因此我可以计算一个线程唤醒了多少次——超过 1000 次,但应用程序只崩溃了一次:

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

所以,我的问题是,每秒唤醒次数如此之多,大约 6000 次/秒,为什么应用程序只崩溃了一次?我怎样才能让它总是因为 EXC_RESOURCE/WAKEUPS 而崩溃?

谢谢!

最佳答案

你解决了吗?我面临同样的问题;

我认为唤醒异常不是崩溃的真正原因;因为我和你一样写了一个demo来重现这个crash,demo运行的时候,我自己退出了demo,也产生了这个日志,也是Exception Subtype: WAKEUPS,所以我认为是其他原因造成的,可能是内存太高;

关于ios - EXC_RESOURCE 崩溃并不总是显示在 iOS 8 上,有很多线程唤醒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26561113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com