more fixed for documentation files (#2016)

This commit is contained in:
Eugene Petrenko
2018-09-07 15:30:07 +03:00
committed by Nikolay Igotti
parent f79146c6ee
commit 8f768fd1df
10 changed files with 13 additions and 69 deletions
+8 -11
View File
@@ -1,9 +1,3 @@
---
type: doc
layout: reference
title: "Concurrency in Kotlin/Native"
---
### Concurrency in Kotlin/Native
Kotlin/Native runtime doesn't encourage a classical thread-oriented concurrency
@@ -60,8 +54,8 @@ title: "Concurrency in Kotlin/Native"
For more complete example please refer to the [workers example](https://github.com/JetBrains/kotlin-native/tree/master/samples/workers)
in the Kotlin/Native repository.
## <a name="transfer"></a>Object transfer and freezing
<a name="transfer"></a>
## Object transfer and freezing
Important invariant that Kotlin/Native runtime maintains is that object is either owned by a single
thread/worker, or is immutable (_shared XOR mutable_). This ensures that the same data has a single mutator, and so no need for
@@ -82,7 +76,8 @@ title: "Concurrency in Kotlin/Native"
is allowed. Currently, Kotlin/Native runtime only freezes enum objects after creation, although additional
autofreezing of certain provably immutable objects could be implemented in the future.
## <a name="detach"></a>Object subgraph detachment
<a name="detach"></a>
## Object subgraph detachment
Object subgraph without external references could be disconnected using `detachObjectGraph` to
a `COpaquePointer` value, which could be stored in `void*` data, so disconnected object subgraphs
@@ -90,7 +85,8 @@ title: "Concurrency in Kotlin/Native"
or worker. Combined with [raw memory sharing](#shared) it allows side channel object transfer between
concurrent threads, if worker mechanisms are insufficient for the particular task.
## <a name="shared"></a>Raw shared memory
<a name="shared"></a>
## Raw shared memory
Considering strong ties of Kotlin/Native with C via interoperability, in conjunction with other mechanisms
mentioned above one could build popular data structures, like concurrent hashmap or shared cache with
@@ -118,7 +114,8 @@ class SharedData(rawPtr: NativePtr) : CStructVar(rawPtr) {
So combined with the top level variable declared above, it allows seeing the same memory from different
threads and building traditional concurrent structures with platform-specific synchronization primitives.
## <a name="top_level"></a>Global variables and singletons
<a name="top_level"></a>
## Global variables and singletons
Frequently, global variables are a source of unintended concurrency issues, so _Kotlin/Native_ implements
following mechanisms to prevent unintended sharing of state via global objects: