All Projects → glessard → Swift Atomics

glessard / Swift Atomics

Licence: bsd-3-clause
Atomic operations bridged from Clang to Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swift Atomics

Evenk
A C++ library for concurrent programming
Stars: ✭ 68 (-37.61%)
Mutual labels:  concurrency
Swift Design Patterns
🚀 The ultimate collection of various Software Design Patterns implemented in Swift [Swift 5.0, 28 Patterns].
Stars: ✭ 85 (-22.02%)
Mutual labels:  concurrency
Job
JOB, make your short-term command as a long-term job. 将命令行规划成任务的工具
Stars: ✭ 98 (-10.09%)
Mutual labels:  concurrency
Async
Async utilities for Golang.
Stars: ✭ 72 (-33.94%)
Mutual labels:  concurrency
Tupl
The Unnamed Persistence Library
Stars: ✭ 83 (-23.85%)
Mutual labels:  concurrency
So 5 5
SObjectizer: it's all about in-process message dispatching!
Stars: ✭ 87 (-20.18%)
Mutual labels:  concurrency
Threadly
Type-safe thread-local storage in Swift
Stars: ✭ 58 (-46.79%)
Mutual labels:  concurrency
Facil.io
Your high performance web application C framework
Stars: ✭ 1,393 (+1177.98%)
Mutual labels:  concurrency
Go Concurrency
This repos has lots of Go concurrency, goroutine and channel usage and best practice examples
Stars: ✭ 84 (-22.94%)
Mutual labels:  concurrency
Swimmer
🏊 Swimmer - An async task pooling and throttling utility for JS
Stars: ✭ 94 (-13.76%)
Mutual labels:  concurrency
Sorty
Fast Concurrent / Parallel Sorting in Go
Stars: ✭ 74 (-32.11%)
Mutual labels:  concurrency
Left Right
A lock-free, read-optimized, concurrency primitive.
Stars: ✭ 1,245 (+1042.2%)
Mutual labels:  concurrency
Java Notes
📚 计算机科学基础知识、Java开发、后端/服务端、面试相关 📚 computer-science/Java-development/backend/interview
Stars: ✭ 1,284 (+1077.98%)
Mutual labels:  concurrency
Libcsp
A concurrency C library 10x faster than Golang.
Stars: ✭ 1,160 (+964.22%)
Mutual labels:  concurrency
Yar
Light, concurrent RPC framework for PHP & C
Stars: ✭ 1,369 (+1155.96%)
Mutual labels:  concurrency
Torrengo
Torrengo is a CLI (command line) program written in Go which concurrently searches torrents from various sources.
Stars: ✭ 67 (-38.53%)
Mutual labels:  concurrency
Kaufmann ex
Kafka backed service library.
Stars: ✭ 86 (-21.1%)
Mutual labels:  concurrency
Go Web Framework Benchmark
⚡ Go web framework benchmark
Stars: ✭ 1,601 (+1368.81%)
Mutual labels:  concurrency
Hark Lang
Build stateful and portable serverless applications without thinking about infrastructure.
Stars: ✭ 103 (-5.5%)
Mutual labels:  concurrency
Imminent
A composable Futures library for Clojure
Stars: ✭ 88 (-19.27%)
Mutual labels:  concurrency

swift-atomics Build Status

Some atomic functions made available to Swift, thanks to Clang.

NOTE: This package is deprecated in favor of the official atomics preview package, Swift Atomics.

The atomic functions available in /usr/include/libkern/OSAtomic.h are quite limiting in Swift, due to impedance mismatches between the type systems of Swift and C. Furthermore, some simple things such as a synchronized load or a synchronized store are not immediately available. On top of that, they have now been deprecated.

Clang, of course, implements the C11 atomic functions — and they're available on Linux.

This project bridges a subset of Clang's C11 atomics support to Swift, as two modules.

The latest version (6.5.0) supports Swift 4.0 and up.

Version 6.2.3 of this package supports versions of Swift as far back as 3.1.1

Module SwiftAtomics

SwiftAtomics has a swift-style interface to provide access to atomic operations. SwiftAtomics implements the following types:

  • AtomicPointer, AtomicMutablePointer, AtomicRawPointer, AtomicMutableRawPointer and AtomicOpaquePointer;
  • AtomicInt and AtomicUInt, as well as signed and unsigned versions of the 8-bit, 16-bit, 32-bit and 64-bit integer types;
  • AtomicBool

The pointer types have the following methods:

  • load, store, swap, and CAS

The integer types have the following methods:

  • load, store, swap, CAS, add, subtract, increment, decrement, bitwiseAnd, bitwiseOr, and bitwiseXor

AtomicBool has the following methods:

  • load, store, swap, CAS, and, or, and xor.

The memory ordering (from <stdatomic.h>) can be set by using the order parameter on each method; the defaults are .acquire for loading operations, .release for storing operations, and .acqrel for read-modify-write operations. Note that memory_order_consume has no equivalent in this module, as (as far as I can tell) clang silently upgrades that ordering to memory_order_acquire, making it impossible (at the moment) to test whether an algorithm can properly use memory_order_consume. This also means nothing is lost by its absence.

The integer types have a value property, as a convenient way to perform a .relaxed load. The pointer types have a pointer property, which performs an .acquire load.

Notes on atomics and the law-of-exclusivity:

Atomic types are useful as synchronization points between threads, and therefore have an interesting relationship with Swift's exclusivity checking. They should be used as members of reference types, or directly captured by closures. They are struct types, so as to be not incur additional memory allocation, but that feature means that if you use the thread sanitizer, it will warn about them.

The types defined in SwiftAtomics work as expected with Swift 5's run-time exclusivity checking when used as members of class instances, but present difficulties when the thread sanitizer is enabled.

In order to use atomics in a way that is acceptable to the thread sanitizer, one must have allocated memory for atomic variables on the heap using UnsafeMutablePointer. If you require compatibility with the thread sanitizer, it is best to use the underlying dependency CAtomics directly or, even better, the official Swift Atomics atomics preview package.

Requirements

This version of SwiftAtomics requires Swift 4.0 or later. On Linux, it also requires Clang 3.6 or later.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].