冻结函数时 kotlin-native freeze() 方法崩溃
kotlin-native freeze() method crashing when freezing a function
我正在尝试冻结一个函数以便能够传递给工作人员。在与函数相同的 class 中,我有一个标记为 ensureNeverFrozen
的变量。这个变量没有用在我试图冻结的函数中,事实上,这个函数什么都不做。
不过,当我尝试冻结函数时,出现以下错误
最小的崩溃重现 code -
Instances of kotlin.Error, kotlin.RuntimeException and subclasses aren't propagated from Kotlin to Objective-C/Swift.
Other exceptions can be propagated as NSError if method has or inherits @Throws annotation.
Uncaught Kotlin exception: kotlin.native.concurrent.FreezingException: freezing of function performWork (Kotlin reflection is not available) has failed, first blocker is []
at 0 lib 0x0000000102502a45 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85
at 1 lib 0x0000000102502125 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85
at 2 lib 0x00000001025265c1 kfun:kotlin.native.concurrent.FreezingException.<init>(kotlin.Any;kotlin.Any)kotlin.native.concurrent.FreezingException + 641
at 3 lib 0x0000000102526a2e ThrowFreezingException + 222
at 4 lib 0x0000000102575833 FreezeSubgraph + 2611
at 5 lib 0x000000010258bcfb Kotlin_Worker_freezeInternal + 27
at 6 lib 0x000000010252673b kfun:kotlin.native.concurrent.freeze@#GENERIC.()Generic + 59
at 7 lib 0x000000010253e310 kfun:com.prateekgrover.lib.KNDispatchQueue.performWorkAsync() + 208
at 8 lib 0x000000010253de1a kfun:com.prateekgrover.lib.Greeting.start() + 186
at 9 lib 0x000000010254168d blockCopyHelper + 573
at 10 ios_kn_sample 0x000000010215471d $sIeg_IeyB_TR + 45 (/Users/prateek.grover/Documents/code/KotlinNative/KotlinNativeSample/core_lib_dup/ios_kn_sample/<compiler-generated>:<unknown>)
at 11 libdispatch.dylib 0x0000000104156d7f _dispatch_call_block_and_release + 12
at 12 libdispatch.dylib 0x0000000104157db5 _dispatch_client_callout + 8
at 13 libdispatch.dylib 0x000000010415a7b9 _dispatch_queue_override_invoke + 1022
at 14 libdispatch.dylib 0x0000000104168632 _dispatch_root_queue_drain + 351
at 15 libdispatch.dylib 0x0000000104168fca _dispatch_worker_thread2 + 130
at 16 libsystem_pthread.dylib 0x00000001045406b3 _pthread_wqthread + 583
at 17 libsystem_pthread.dylib 0x00000001045403fd start_wqthread + 13
对上述行为有任何解释吗?
我想你指的是这个
actual class KNDispatchQueue {
@ThreadLocal
actual companion object Singleton {
actual val sharedInstance: KNDispatchQueue = KNDispatchQueue()
}
private var workQueue: MutableList<KNWork> = mutableListOf()
init {
workQueue.ensureNeverFrozen()
}
actual fun performWorkAsync() {
::performWork.freeze()
}
fun performWork() {
}
}
该函数是 class 的一部分。假设它试图冻结自身的那个实例,它也会冻结图形的其余部分。我注释掉了 ensureNeverFrozen
它冻结了。
您的语法 ::performWork
指向实例引用。
我正在尝试冻结一个函数以便能够传递给工作人员。在与函数相同的 class 中,我有一个标记为 ensureNeverFrozen
的变量。这个变量没有用在我试图冻结的函数中,事实上,这个函数什么都不做。
不过,当我尝试冻结函数时,出现以下错误
最小的崩溃重现 code -
Instances of kotlin.Error, kotlin.RuntimeException and subclasses aren't propagated from Kotlin to Objective-C/Swift.
Other exceptions can be propagated as NSError if method has or inherits @Throws annotation.
Uncaught Kotlin exception: kotlin.native.concurrent.FreezingException: freezing of function performWork (Kotlin reflection is not available) has failed, first blocker is []
at 0 lib 0x0000000102502a45 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85
at 1 lib 0x0000000102502125 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85
at 2 lib 0x00000001025265c1 kfun:kotlin.native.concurrent.FreezingException.<init>(kotlin.Any;kotlin.Any)kotlin.native.concurrent.FreezingException + 641
at 3 lib 0x0000000102526a2e ThrowFreezingException + 222
at 4 lib 0x0000000102575833 FreezeSubgraph + 2611
at 5 lib 0x000000010258bcfb Kotlin_Worker_freezeInternal + 27
at 6 lib 0x000000010252673b kfun:kotlin.native.concurrent.freeze@#GENERIC.()Generic + 59
at 7 lib 0x000000010253e310 kfun:com.prateekgrover.lib.KNDispatchQueue.performWorkAsync() + 208
at 8 lib 0x000000010253de1a kfun:com.prateekgrover.lib.Greeting.start() + 186
at 9 lib 0x000000010254168d blockCopyHelper + 573
at 10 ios_kn_sample 0x000000010215471d $sIeg_IeyB_TR + 45 (/Users/prateek.grover/Documents/code/KotlinNative/KotlinNativeSample/core_lib_dup/ios_kn_sample/<compiler-generated>:<unknown>)
at 11 libdispatch.dylib 0x0000000104156d7f _dispatch_call_block_and_release + 12
at 12 libdispatch.dylib 0x0000000104157db5 _dispatch_client_callout + 8
at 13 libdispatch.dylib 0x000000010415a7b9 _dispatch_queue_override_invoke + 1022
at 14 libdispatch.dylib 0x0000000104168632 _dispatch_root_queue_drain + 351
at 15 libdispatch.dylib 0x0000000104168fca _dispatch_worker_thread2 + 130
at 16 libsystem_pthread.dylib 0x00000001045406b3 _pthread_wqthread + 583
at 17 libsystem_pthread.dylib 0x00000001045403fd start_wqthread + 13
对上述行为有任何解释吗?
我想你指的是这个
actual class KNDispatchQueue {
@ThreadLocal
actual companion object Singleton {
actual val sharedInstance: KNDispatchQueue = KNDispatchQueue()
}
private var workQueue: MutableList<KNWork> = mutableListOf()
init {
workQueue.ensureNeverFrozen()
}
actual fun performWorkAsync() {
::performWork.freeze()
}
fun performWork() {
}
}
该函数是 class 的一部分。假设它试图冻结自身的那个实例,它也会冻结图形的其余部分。我注释掉了 ensureNeverFrozen
它冻结了。
您的语法 ::performWork
指向实例引用。