title: Deadlock with GCD and webView
body: <p>I've found an issue that seems to be causing a deadlock in WebKit. If I run this code from my main thread, I rightly see an alert. I can tap on the "OK" button on the alert and it dismisses and all is working well:</p>
  
  <pre><code>[theWebView stringByEvaluatingJavaScriptFromString:@"alert('hi');"];
  </code></pre>
  
  <p>If I make a slight modification, then the alert message still appears, but the OK button cannot be tapped on - you cannot dismiss the alert and if you break into the app it is hung in the <code>stringByEvaluatingJavaScriptFromString</code> call:</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      dispatch_async(dispatch_get_main_queue(), ^{
          [theWebView stringByEvaluatingJavaScriptFromString:@"alert('hi');"];
      });
  });
  </code></pre>
  
  <p>The <em>only</em> different in these two is that in the second one, it is running the JS in the main thread in the context of a dispatch queue.</p>
  
  <p>On the other hand, if I do the following, then the hang does not occur:</p>
  
  <pre><code>- (void) showHi:(id) it
  {
      [(UIWebView*)it stringByEvaluatingJavaScriptFromString:@"alert('hi');"];
  }
  
  ....
  
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      [self performSelectorOnMainThread:@selector(showHi:) withObject:theWebView waitUntilDone:NO];
  });
  </code></pre>
  
  <p>Can someone shine some light on what is going wrong to cause the hang?</p>
  
  <p>EDIT:</p>
  
  <p>Related questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/11530050/perform-ui-changes-on-main-thread-using-dispatch-async-or-performselectoronmaint">Perform UI Changes on main thread using dispatch_async or performSelectorOnMainThread?</a><br>
  <a href="https://stackoverflow.com/questions/9335434/whats-the-difference-between-performselectoronmainthread-and-dispatch-async-on-m">Whats the difference between performSelectorOnMainThread and dispatch_async on main queue?</a><br>
  <a href="https://stackoverflow.com/questions/5225130/grand-central-dispatch-gcd-vs-performselector-need-a-better-explanation">Grand Central Dispatch (GCD) vs. performSelector - need a better explanation</a></p>
  
  <p>Very similar question:</p>
  
  <p><a href="https://stackoverflow.com/questions/11593900/uiwebview-stringbyevaluatingjavascriptfromstring-hangs-on-ios5-0-5-1-when-called#comment29257640_11593900">UIWebView stringByEvaluatingJavaScriptFromString hangs on iOS5.0/5.1 when called using GCD</a></p>