Comments (4)
Interesting question: I've never seen Apple advise that in custom accessor methods and it's not in any of their NSOperation
subclass examples (neither in Configuring Operations for Concurrent Execution nor their new Swift Advanced NSOperations example).
from afhttpsessionoperation.
Well according to documentation:
isExecuting
isFinishedYour implementations of these methods must be safe to call from other threads simultaneously. You must also generate the appropriate KVO notifications for the expected key paths when changing the values reported by these methods.
I suppose same goes for setExecuting
and setFinished
because they access the same ivars.
from afhttpsessionoperation.
The "Multicore Considerations" section of the NSOperation class reference says something very similar:
Multicore Considerations
The
NSOperation
class is itself multicore aware. It is therefore safe to call the methods of an NSOperation object from multiple threads without creating additional locks to synchronize access to the object. This behavior is necessary because an operation typically runs in a separate thread from the one that created and is monitoring it.When you subclass
NSOperation
, you must make sure that any overridden methods remain safe to call from multiple threads. If you implement custom methods in your subclass, such as custom data accessors, you must also make sure those methods are thread-safe. Thus, access to any data variables in the operation must be synchronized to prevent potential data corruption. For more information about synchronization, see Threading Programming Guide.
I've modified my code accordingly.
It's just fascinating that Apple universally ignores this advice in their own code.
from afhttpsessionoperation.
Multi-threading is hard. Thanks for update!
from afhttpsessionoperation.
Related Issues (14)
- AFHTTPSessionOperation not run on background HOT 1
- Why the location of 'if' in 'setExecuting' and 'setFinished' is different? HOT 2
- No method to create operation from NSURLRequest HOT 2
- cancelAllOperations HOT 1
- Semantic issue in library after updating xcode
- The App is Crashing on AsynchroniousOperetionManager.m file while called setFinished method
- app crash with EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x000000000000000a
- (minor) missing parameters in 'auto-filled' method sigs HOT 1
- batch requests HOT 1
- Add cocoapods spec HOT 1
- Operation went isFinished=YES without being started by the queue HOT 1
- Not Work for dependency request HOT 1
- How can i implement "DataTask" AFHTTPSessionManager’category in swift? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from afhttpsessionoperation.