Allow sharing top level vals with types marked as frozen. (#2086)

This commit is contained in:
Nikolay Igotti
2018-09-19 11:23:32 +03:00
committed by GitHub
parent 87a7a9630a
commit 45032f0b88
3 changed files with 93 additions and 2 deletions
+6
View File
@@ -659,6 +659,12 @@ task worker9(type: RunKonanTest) {
source = "runtime/workers/worker9.kt"
}
task worker10(type: RunKonanTest) {
disabled = (project.testTarget == 'wasm32') // Workers need pthreads.
goldValue = "OK\n"
source = "runtime/workers/worker10.kt"
}
task freeze0(type: RunKonanTest) {
disabled = (project.testTarget == 'wasm32') // No workers on WASM.
goldValue = "frozen bit is true\n" +
@@ -0,0 +1,81 @@
package runtime.workers.worker10
import kotlin.test.*
import kotlin.native.concurrent.*
class Data(val x: Int)
val topInt = 1
val topString = "string"
var topStringVar = "string"
val topSharedStringWithGetter: String
get() = "top"
val topData = Data(42)
@SharedImmutable
val topSharedData = Data(43)
@Test fun runTest() {
val worker = Worker.start()
assertEquals(1, topInt)
assertEquals("string", topString)
assertEquals(42, topData.x)
assertEquals(43, topSharedData.x)
assertEquals("top", topSharedStringWithGetter)
worker.execute(TransferMode.SAFE, { -> }, {
it -> topInt == 1
}).consume {
result -> assertEquals(true, result)
}
worker.execute(TransferMode.SAFE, { -> }, {
it -> topString == "string"
}).consume {
result -> assertEquals(true, result)
}
worker.execute(TransferMode.SAFE, { -> }, {
it -> try {
topStringVar == "string"
} catch (e: IncorrectDereferenceException) {
false
}
}).consume {
result -> assertEquals(false, result)
}
worker.execute(TransferMode.SAFE, { -> }, {
it -> try {
topSharedStringWithGetter == "top"
} catch (e: IncorrectDereferenceException) {
false
}
}).consume {
result -> assertEquals(true, result)
}
worker.execute(TransferMode.SAFE, { -> }, {
it -> try {
topData.x == 42
} catch (e: IncorrectDereferenceException) {
false
}
}).consume {
result -> assertEquals(false, result)
}
worker.execute(TransferMode.SAFE, { -> }, {
it -> try {
topSharedData.x == 43
} catch (e: Throwable) {
false
}
}).consume {
result -> assertEquals(true, result)
}
worker.requestTermination().result
println("OK")
}