I have a property declared as the following:
@property(assign) BOOL die;
One thread continuously checks if it should die by looking to see if that variable has changed to YES. When that die is set to YES (by a user clicking a button), the other thread that is grinding away still sees it as NO. I've put careful traces through the code and seen that the variable definitely doesn't show up as modified. What is going on here?
Does each thread contain its own cache of the variable? In Java, my native language, I would have set the 'volatile'开发者_运维技巧 keyword on it to remove local thread caching on the property.
Is this something you can do in obj-c or am I on the wrong track?
different threads might be checking different instances. make sure that both threads are accessing to the same copy of that parameter
You might be better using using notification centers, and so that the listener is notified when it is changed.
精彩评论