views:

215

answers:

1

I have an issue that looks like a race condition with a webview callback and a location manager callback that interact with the same variables and an alert dialog - the dialog is created in the location callback and should be dismissed in the webview callback. I thought that the delegate callbacks for standard objects like the webview and core location would be run in the main thread - is that not correct?

A: 

If in doubt then you can do something like this:

- (void) someCallback
{
    if ([NSThread isMainThread] ==  NO) {
        [self performSelectorOnMainThread: @selector(someCallback)];
    }
}

To make sure that you are always executing callback methods on the main thread and thus preventing concurrency issues.

You can also use a @synchronized block of course, but in my experience it is much better to rely on the synchronous nature of executing methods on the main thread.

St3fan
Good tip. Thanks. (and they do run in the main thread).
Wendy