Skip to content

pcoltau/ReadersWriterLock

Repository files navigation

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.

About

A Swift implementation of the readers-writer lock.

Resources

License

Stars

Watchers

Forks

Packages

No packages published