fix broken links for kotlin web site (#628)
* fix broken links for Kotlin web site
diff --git a/docs/shared-mutable-state-and-concurrency.md b/docs/shared-mutable-state-and-concurrency.md
index 7574e46..9e90d59 100644
--- a/docs/shared-mutable-state-and-concurrency.md
+++ b/docs/shared-mutable-state-and-concurrency.md
@@ -61,6 +61,8 @@
import kotlin.coroutines.experimental.*
-->
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
suspend fun CoroutineScope.massiveRun(action: suspend () -> Unit) {
val n = 100 // number of coroutines to launch
@@ -77,11 +79,15 @@
}
```
+</div>
+
<!--- INCLUDE .*/example-sync-([0-9a-z]+).kt -->
We start with a very simple action that increments a shared mutable variable using
multi-threaded [Dispatchers.Default] that is used in [GlobalScope].
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
var counter = 0
@@ -93,6 +99,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-01.kt)
<!--- TEST LINES_START
@@ -107,6 +115,8 @@
the thread pool is running in only one thread in this case. To reproduce the problem you'll need to make the
following change:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
val mtContext = newFixedThreadPoolContext(2, "mtPool") // explicitly define context with two threads
var counter = 0
@@ -119,6 +129,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-01b.kt)
<!--- TEST LINES_START
@@ -130,6 +142,8 @@
There is common misconception that making a variable `volatile` solves concurrency problem. Let us try it:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
@Volatile // in Kotlin `volatile` is an annotation
var counter = 0
@@ -142,6 +156,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-02.kt)
<!--- TEST LINES_START
@@ -160,6 +176,8 @@
operations that needs to be performed on a shared state.
In the case of a simple counter we can use `AtomicInteger` class which has atomic `incrementAndGet` operations:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
var counter = AtomicInteger()
@@ -171,6 +189,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-03.kt)
<!--- TEST ARBITRARY_TIME
@@ -189,6 +209,8 @@
the single event-dispatch/application thread. It is easy to apply with coroutines by using a
single-threaded context.
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
val counterContext = newSingleThreadContext("CounterContext")
var counter = 0
@@ -203,6 +225,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-04.kt)
<!--- TEST ARBITRARY_TIME
@@ -220,6 +244,8 @@
the single-threaded context to start with.
Here we use [CoroutineScope()] function to convert coroutine context reference to [CoroutineScope]:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
val counterContext = newSingleThreadContext("CounterContext")
var counter = 0
@@ -232,6 +258,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-05.kt)
<!--- TEST ARBITRARY_TIME
@@ -251,6 +279,8 @@
There is also [withLock] extension function that conveniently represents
`mutex.lock(); try { ... } finally { mutex.unlock() }` pattern:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
val mutex = Mutex()
var counter = 0
@@ -265,6 +295,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-06.kt)
<!--- TEST ARBITRARY_TIME
@@ -293,6 +325,8 @@
primitive, that represents a single value that will be known (communicated) in the future,
is used here for that purpose.
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
// Message types for counterActor
sealed class CounterMsg
@@ -300,8 +334,12 @@
class GetCounter(val response: CompletableDeferred<Int>) : CounterMsg() // a request with reply
```
+</div>
+
Then we define a function that launches an actor using an [actor] coroutine builder:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
// This function launches a new counter actor
fun CoroutineScope.counterActor() = actor<CounterMsg> {
@@ -315,8 +353,12 @@
}
```
+</div>
+
The main code is straightforward:
+<div class="sample" markdown="1" theme="idea" data-highlight-only>
+
```kotlin
fun main(args: Array<String>) = runBlocking<Unit> {
val counter = counterActor() // create the actor
@@ -331,6 +373,8 @@
}
```
+</div>
+
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-sync-07.kt)
<!--- TEST ARBITRARY_TIME