Skip to content

Genaro-Chris/swift-concurrency-primitives

Repository files navigation

swift-concurrency-primitives

License

A concurrency primitive package written in swift for swift developers

Overview

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.

Installation

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

Features

This package provides various basic concurrency primitives which can be categorized into the following

Synchronization

This package also provides some constructs that synchronize concurrent accesses to a critical code section in order to avoid data race bugs

Threads Co-ordination

This package even provide some constructs for co-ordination for threads by waiting for all threads to finish their execution

Message Passing

This package provides some concurrency constructs that enable threads share memory by communicating values as message.

ThreadPool

This package provides some concurrency construct that efficiently manage a fized size of worker threads ready to execute code.

Call Once

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

Documentation

The API documentation can also be accessed here

ExampleUsage

For some practical usage for this package, take a good look at ExampleApp

Contributing

I highly welcome and encourage all sorts of contributions from all swift developers.

License

This package is released under Apache-2.0 license. See LICENSE for more information.