草庐IT

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

coder 2023-09-30 原文

根据 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/

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

  1. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  2. Ruby Readline 在向上箭头上使控制台崩溃 - 2

    当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby​​安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少

  3. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  4. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  5. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  6. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  7. ruby - 在多个线程中引用类方法会导致自动加载循环依赖崩溃 - 2

    代码:threads=[]Thread.abort_on_exception=truebegin#throwexceptionsinthreadssowecanseethemthreadseputs"EXCEPTION:#{e.inspect}"puts"MESSAGE:#{e.message}"end崩溃:.rvm/gems/ruby-2.1.3@req/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:478:inload_missing_constant':自动加载常量MyClass时检测到循环依赖稍加研究后,

  8. ruby - 为 IO::popen 拯救 "command not found" - 2

    当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby​​1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#

  9. ruby - IO::EAGAINWaitReadable:资源暂时不可用 - 读取会阻塞 - 2

    当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab

  10. ruby - 执行过期异常使 Ruby 线程崩溃,但处理了 Timeout::Error - 2

    任何人都可以解释为什么当对方法的调用看起来像这样时我可能会看到这个堆栈(由HTTParty::post请求引起):beginresponse=HTTParty::post(url,options)rescuelogger.warn("Couldnotpostto#{url}")rescueTimeout::Errorlogger.warn("Couldnotpostto#{url}:timeout")end堆栈:/usr/local/lib/ruby/1.8/timeout.rb:64:in`timeout'/usr/local/lib/ruby/1.8/net/protocol.rb

随机推荐