gpt4 book ai didi

iOS 使用 detachNewThreadSelector 卡住和线程化

转载 作者:行者123 更新时间:2023-11-29 04:08:24 25 4
gpt4 key购买 nike

我正在开发一个由其他人设计的应用程序。该应用程序充满了这样的调用:

[NSThread detachNewThreadSelector:@selector(loadPhotoImage) toTarget:self withObject:nil];

DownloadPhotoThread *thread = [[DownloadPhotoThread alloc] initWithFriendArray:_friendsList delegate:self];
[self.arrDownloadThreads addObject:thread];
[thread start];

随机地我会遇到整个用户界面锁定的情况,并且手机/模拟器不再响应触摸。需要明确的是,该设备永远不会解冻。如果我在调试 session 期间暂停,我会看到一个线程位于 start 或 detachNewThreadSelector 行上。

今天,我能够缩小发生这些锁定的原因范围。我刚刚添加了 Zendesk 表单 Controller (此处找到:https://github.com/zendesk/zendesk_ios_sdk/blob/master/DropboxSampleApp/FormViewController.m)

其中有以下代码:

- (void) textViewDidChange:(UITextView *)textView
{
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row > 1) {
CGSize s = [description sizeThatFits:CGSizeMake(description.frame.size.width, 10000)];
float dh = MAX(s.height, 115);
description.frame = CGRectMake(description.frame.origin.x,
description.frame.origin.y,
description.frame.size.width,
dh);
return dh;
}
return 44.0;
}

我可以通过键入一个字符并反复返回到此文本框来轻松重现锁定情况。 (这会调整表格 View 的高度)

在某些情况下,我可以通过用这样的dispatch_async() block 包装违规者来防止锁定情况:

DownloadPhotoThread *thread = [[DownloadPhotoThread alloc] initWithFriendArray:_friendsList delegate:self];
[self.arrDownloadThreads addObject:thread];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[thread start];
});

但在其他情况下我不能,因为有问题的代码位于复杂的库中,例如 ASIHTTPRequest 或 XMPPFramework。您对这里到底发生了什么有什么建议吗?

另一件事。当我在这种情况下暂停时,主线程是这样说的:

Thread 1
com.apple.main-thread
0 objc_msgSend
....
25 UIApplicationMain
26 main

暂停和取消暂停总是会在 objc_msgSend 内的某些汇编指令处找到 main。

感谢您的帮助,因为我在这里遇到了严重的困难。

最佳答案

事实证明,崩溃是由 https://github.com/zendesk/zendesk_ios_sdk/ 中的错误引起的。我已提出拉取请求并提交给他们进行审核。

关于iOS 使用 detachNewThreadSelector 卡住和线程化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14825440/

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