Skip to content

Common Thread class (and snychronization primitives) for Kotlin/Multiplatform.

License

Notifications You must be signed in to change notification settings

karmakrafts/Filament

Repository files navigation

Filament

Common Thread class (and snychronization primitives) for Kotlin/Multiplatform. This allows true, pure parallelism in Kotlin where controlling an OS thread directly is feasable.
The library also offers various utilities and integration with other libraries.

Supported platforms

  • Windows
  • Linux
  • macOS
  • iOS
  • watchOS
  • tvOS
  • Android
  • Android Native
  • JVM

Features

  • Thread as a general purpose wrapper around system threads
    • java.lang.Thread on JVM/Android
    • libpthread on Kotlin/Native targets
    • Unified support for thread names
    • Unified support for thread IDs
  • Mutex as a simple mutex implementation
    • Lock guards as integration with RAkII
  • SharedMutex as a reentrant read-write lock implementation
    • Lock guards as integration with RAkII
  • Executor interface for bridging different APIs
  • ThreadPool as a simple work-stealing thread pool implementation
    • Default implementation of Executor
  • Future interface for unifying awaitable objects
  • CompletableFuture type with atomic state as a default Future implementation
    • Create uncompleted futures with any default value
    • Create a value supplying task from an Executor and a block
  • java.util.concurrent integration
    • Use any filament Executor as a JVM Executor
  • kotlinx.coroutines integration
    • Use any Executor as a CoroutineDispatcher
    • Use any Future<T> as a Deferred<T> and vice versa
    • Use CompletableFuture.asyncSuspend to create awaitable objects from a suspend block
    • Use Future.awaitSuspend to await any future by yielding the coroutine

More features may be added in the future. Contributions are welcome! :)

How to use it

First, add the official Karma Krafts maven repository to your settings.gradle.kts:

pluginManagement {
    repositories {
        // Snapshots are available from the Karma Krafts repository or Maven Central Snapshots
        maven("https://files.karmakrafts.dev/maven")
        maven("https://central.sonatype.com/repository/maven-snapshots")
        // Releases are mirrored to the central M2 repository
        mavenCentral()
    }
}

dependencyResolutionManagement {
    repositories {
        // Snapshots are available from the Karma Krafts repository or Maven Central Snapshots
        maven("https://files.karmakrafts.dev/maven")
        maven("https://central.sonatype.com/repository/maven-snapshots")
        // Releases are mirrored to the central M2 repository
        mavenCentral()
    }
}

Then add a dependency on the library in your buildscript:

kotlin {
    commonMain {
        dependencies {
            implementation("dev.karmakrafts.filament:filament:<version>")
        }
    }
}

About

Common Thread class (and snychronization primitives) for Kotlin/Multiplatform.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages