Giter Site home page Giter Site logo

Thread safety for OSX about sttwitter HOT 4 CLOSED

nst avatar nst commented on July 18, 2024
Thread safety for OSX

from sttwitter.

Comments (4)

nst avatar nst commented on July 18, 2024

STTwitter uses asynchronous network requests so it can be used from main thread without slowing the main application. I'm afraid that declaring properties as 'nonatomic' would induce users in error and let them think STTwitter is supposed to be used from a background thread.

from sttwitter.

Mazyod avatar Mazyod commented on July 18, 2024

They are currently declared as nonatomic, so they aren't thread-safe. In a Mac OS project, it is very common for developers to have several running threads accessing the same resource, and in this case, the STTwitter API. This makes the properties prone to race conditions and the such. I am not really en expert, but I picked this up from best practices Mac OS programmers use vs iOS development.

from sttwitter.

nst avatar nst commented on July 18, 2024

You are right when you say that STTwitter isn't thread safe. It should always be used from the main thread, as many Apple frameworks such as UIKit http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKit_Framework/Introduction/Introduction.html

STTwitter properties are always accessed from the main thread so they don't need to be atomic. nonatomic is faster and safe in this situation.

Using STTwitterAPIWrapper instances from background threads would raise many issues and declaring properties as atomic wouldn't be enough to fix them.

So, you can safely use STTwitter from the main thread, update your model and your UI from successBlock and errorBlock callbacks. That's how it's supposed to be used.

If you meet performance issues, tell me and I'll have a look.

from sttwitter.

Mazyod avatar Mazyod commented on July 18, 2024

I see, ok. Thank you very much.

from sttwitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.