[![CI Status](http://img.shields.io/travis/Jiakai Lian/JKLThreadSafeOperator.svg?style=flat)](https://travis-ci.org/Jiakai Lian/JKLThreadSafeOperator)
Make a class thread-safe could be painful, as involving wrapping all your public methods into GCD operations.
This operator is designated to perform thread-safe operations by simply wrapping read & write operations into corresponding blocks. (For performance comparision between different implementations, please check another repo ThreadSafeClassDesign). So without changing original model classes, the project could benefit from multi-threading without compromising the stability.
The main idea behind the scene is applying concurrent read and exclusive write model on a concurrent GCD queue. Additionally, this operator maintains a simple cache to manage queues for each type of class.
To run the example project, clone the repo, and run pod
install from the Example directory first.
__block NSUInteger studentsCount;
[JKLThreadSafeOperator syncReadWithObject:course readBlock:^(JKLCourse * innerReadOnlyCourse) {
studentsCount = [innerReadOnlyCourse students].count;
}];
[JKLThreadSafeOperator barrierAsyncWriteWithObject:course writeBlock:^(JKLCourse * innerWritableCourse) {
[innerWritableCourse addStudentWithStudentName:@"Bob"];
}];
JKLThreadSafeOperator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "JKLThreadSafeOperator"
Jiakai Lian, jiakai.lian@gmail.com
JKLThreadSafeOperator is available under the MIT license. See the LICENSE file for more info.