A concurrency primitive package written in swift for swift developers
This package provides various basic concurrency primitives such as Lock
, Locked
which is similar to Mutex
in other languages, ThreadPool
, Channel
and Queue
.
This package aims to provide concurrency primitives that are readily available in other programming languages but not in swift.
Most of the constructs shouldn't be used in async context because they block a thread's execution flow thereby violating the swift's runtime contract: forward progress of thread execution.
This package serves as an alternative to the Dispatch
module of the swift language with a few more concurrency constructs.
To use this package
First, add the following package dependency to your package.swift
file
.package(url: "https://github.com/Genaro-Chris/swift-concurrency-primitives", branch: "main")
Then add the Primitives
library to the target(s) you want to use it
.product(name: "Primitives", package: "swift-concurrency-primitives")
Then finally
import Primitives
This package provides various basic concurrency primitives which can be categorized into the following
This package also provides some constructs that synchronize concurrent accesses to a critical code section in order to avoid data race bugs
This package even provide some constructs for co-ordination for threads by waiting for all threads to finish their execution
This package provides some concurrency constructs that enable threads share memory by communicating values as message.
This package provides some concurrency construct that efficiently manage a fized size of worker threads ready to execute code.
A synchronization primitive which provides a way of executing code exactly once regardless of how many times it was called in a thread-safe manner
And many more others, or to be added
The API documentation can also be accessed here
For some practical usage for this package, take a good look at ExampleApp
I highly welcome and encourage all sorts of contributions from all swift developers.
This package is released under Apache-2.0 license. See LICENSE for more information.