@@ -21,6 +21,7 @@ The idiomatic way to use atomic operations in Kotlin.
21
21
* [ JDK9 VarHandle] ( #varhandles-with-java-9 ) .
22
22
* [ Arrays of atomic values] ( #arrays-of-atomic-values ) .
23
23
* [ User-defined extensions on atomics] ( #user-defined-extensions-on-atomics )
24
+ * [ Locks] ( #locks )
24
25
* [ Testing of lock-free data structures] ( #testing-lock-free-data-structures-on-jvm ) .
25
26
26
27
## Example
@@ -124,7 +125,7 @@ Configure add apply plugin just like for [JVM](#jvm).
124
125
### Native
125
126
126
127
This library is available for Kotlin/Native (` atomicfu-native ` ).
127
- Kotlin/Native uses Gradle metadata and needs Gradle version 5.3 or later
128
+ Kotlin/Native uses Gradle metadata and needs Gradle version 5.3 or later.
128
129
See [ Gradle Metadata 1.0 announcement] ( https://blog.gradle.org/gradle-metadata-1.0 ) for more details.
129
130
Apply the corresponding plugin just like for [ JVM] ( #jvm ) .
130
131
@@ -279,6 +280,26 @@ be public and be used outside of the module they are defined in. For example:
279
280
private inline fun AtomicBoolean.tryAcquire (): Boolean = compareAndSet(false , true )
280
281
```
281
282
283
+ ### Locks
284
+
285
+ This project includes ` kotlinx.atomicfu.locks ` package providing multiplatform locking primitives that
286
+ require no additional runtime dependencies on Kotlin/JVM and Kotlin/JS with a library implementation for
287
+ Kotlin/Native.
288
+
289
+ * ` SynchronizedObject ` is designed for inheritance. You write ` class MyClass : SynchronizedObject() ` and then
290
+ use ` synchronized(instance) { ... } ` extension function similarly to the
291
+ [ synchronized] ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/synchronized.html )
292
+ function from the standard library that is available for JVM. The ` SynchronizedObject ` superclass gets erased
293
+ (transformed to ` Any ` ) on JVM and JS, with ` synchronized ` leaving no trace in the code on JS and getting
294
+ replaced with built-in monitors for locking on JVM.
295
+
296
+ * ` ReentrantLock ` is designed for delegation. You write ` val lock = reentrantLock() ` to construct its instance and
297
+ use ` lock ` /` tryLock ` /` unlock ` functions or ` lock.withLock { ... } ` extension function similarly to the way
298
+ [ jucl.ReentrantLock] ( https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/ReentrantLock.html )
299
+ is used on JVM. On JVM it is a typealias to the later class, erased on JS.
300
+
301
+ Condition variables (` notify ` /` wait ` and ` signal ` /` await ` ) are not supported.
302
+
282
303
### Testing lock-free data structures on JVM
283
304
284
305
You can optionally test lock-freedomness of lock-free data structures using
0 commit comments