gpt4 book ai didi

objective-c - 多线程从何而来?

转载 作者:行者123 更新时间:2023-11-29 11:10:52 26 4
gpt4 key购买 nike

我有一个多线程问题。在我排序和修改 NSOrderedSet 的那段代码周围适当放置 @synchronized{} 似乎可以解决我正在读回的部分中的问题。我现在的问题是试图弄清楚我的另一个线程来自哪里,以便我可以更好地理解我的代码。这些片段中的任何一个都会引起新话题吗?

CADisplayLink* gameTimer;
gameTimer = [CADisplayLink
displayLinkWithTarget:self
selector:@selector(updateDisplay:)];

[gameTimer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

和/或这会启动一个线程吗?

 AURenderCallbackStruct callbackStruct;
callbackStruct.inputProc = PerformThru;
callbackStruct.inputProcRefCon = &_effectState;

AudioUnitSetProperty( _effectState.rioUnit,
kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Global,
bus0,
&callbackStruct,
sizeof(callbackStruct);
AudioOutputUnitStart(_effectState.rioUnit);

我猜是后者,因为在 PerformThru 函数中我开始看到像

这样的调试消息
   Object 0x682ec20 of class __NSOrderedSetM autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

但是,在 main 中我有 @autoreleasepool.. 所以我猜是有什么东西导致了另一个线程。

最佳答案

音频单元渲染回调将在私有(private)(核心音频)后台线程中调用。您可以通过在 PerformThru() 中放置一个断点并注意调试器停止的堆栈帧不在主线程/队列中来看到这一点。

关于objective-c - 多线程从何而来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11638814/

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