Document potentially cyclic cases in ownership transfer and add test. (#3207)
This commit is contained in:
@@ -58,5 +58,27 @@ fun withLock(op: () -> Unit) {
|
||||
println("frozen OK")
|
||||
}.freeze())
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
|
||||
class Node(var node: Node?, var outher: Node?)
|
||||
|
||||
fun makeCyclic(): Node {
|
||||
val inner = Node(null, null)
|
||||
inner.node = inner
|
||||
val outer = Node(null, null)
|
||||
inner.outher = outer
|
||||
return outer
|
||||
}
|
||||
|
||||
@Test fun runTest4() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val future = worker.execute(TransferMode.SAFE, { }) {
|
||||
makeCyclic().also {
|
||||
kotlin.native.internal.GC.collect()
|
||||
}
|
||||
}
|
||||
assert(future.result != null)
|
||||
worker.requestTermination().result
|
||||
}
|
||||
@@ -76,6 +76,9 @@ public inline class Worker @PublishedApi internal constructor(val id: Int) {
|
||||
* explicitly stored in object produced by [producer]. Scheduled job is being executed by the worker,
|
||||
* and result of such a execution is being disconnected from worker's object graph. Whoever will consume
|
||||
* the future, can use result of worker's computations.
|
||||
* Note, that some technically disjoint subgraphs may lead to `kotlin.IllegalStateException`
|
||||
* so `kotlin.native.internal.GC.collect()` could be called in the end of `producer` and `job`
|
||||
* if garbage cyclic structures or other uncollected objects refer to the value being transferred.
|
||||
*
|
||||
* @return the future with the computation result of [job]
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user