Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.54 KB

README.md

File metadata and controls

54 lines (36 loc) · 1.54 KB

ReadersWriterLock

CI Status Version License Platform

A readers-writer lock is a shared-exclusive lock. It allows for concurrent read locks, but require exclusive access to write locks.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

ReadersWriterLock is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ReadersWriterLock'

Usage

// import the module in your source
import ReadersWriterLock

// Create a normal dictionary
var dictionary = [String: String]()

// Create the lock
let lock = ReadersWriterLock()

// Write values to the dictionary using the write lock
lock.withWriteLock {
    dictionary["value"] = "test"
}

// Read values from the dictionary using a read lock
let value = lock.withReadLock {
    dictionary["value"]!
}

print(value) // "test"

Author

[email protected]

License

ReadersWriterLock is available under the MIT license. See the LICENSE file for more info.