7

Perhaps one Iphone Guru can enlighten me...

I've been going line-by-line and eliminating any threads calls / NSInvocation's that use the UIKit, as a matter of fact, I have made 100% sure that NO UIKit crap gets called from any-where else except the MainThread I.E...

if([NSThread isMainThread])
{
  blah....
  Call UIKit Crap here!
  and blah....
}

So far so good, but then after I created a thread to do a http POST (using LibCurl) I started getting this:

"void _WebThreadLockFromAnyThread(bool), 0x4d7bbe0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread."

Like WTF...? I can't even Use Curl from a Thread, to do a Network Intensive Operation..? I just moved this damn thing, off the mainThread, to Comply with Their (Apple's) UIKit's strict, "Don't call any UIKit crap, except from the Main Thread...PERIOD or Else!!!"

So I move the "UiAlertView & UIActivityIndicator" back onto the main thread (No error messages before) and create a thread to do the curl POST operation... Now that I am in compliance, and then all of a sudden, I start getting this message...?

Can anyone explain where I am suppose to put this Network intensive operation, which, by the way, will cause the any UIActivity Indicator's / UIAlertView's to freeze in their tracks...

Thanks in Advance...

[I am just a linux programmer in sheep's clothing]

Slee
  • 27,498
  • 52
  • 145
  • 243
  • 1
    I don't think "WTF" will help you get good answers. This is not a right forum for it. – Praveen S Jun 09 '11 at 07:21
  • Where do you update your uialertview? In your curl callback you need to post the event to main thread. Post some code. – Praveen S Jun 09 '11 at 07:22
  • NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; PostComment(text); // curl call [self performSelectorOnMainThread:@selector(stopIndicator) withObject:nil waitUntilDone:NO]; [pool release]; –  Jun 09 '11 at 07:46
  • " In your curl callback you need to post the event to main thread " Come Again...? Are you joking...? Can you point me to this documentation, that states I need to post an event to the main thread, that has nothing at all to do with it... Thank you! –  Jun 09 '11 at 07:51
  • 1
    http://stackoverflow.com/questions/4672254/uikit-should-not-be-called-from-a-secondary-thread -- The whole point that you are getting an error shows you are not sure what you are doing and are surely doing it wrong. If you are lil more willing to learn people here can point you in right direction. – Praveen S Jun 09 '11 at 08:05
  • Ok... thank you.... I just don't know what it is with kids these days and their attitudes... Thank you... Sorry, I didn't just take the, "Become an Iphone programmer in 15 days" exam... Like I said I am NOT a iphone programmer, but read / write locks have been around for quite a while, especially when it has to do with network traffic... And maybe you might read up a bit about that stuff before you lambast someone over asking a question...? Thank you! –  Jun 09 '11 at 08:11
  • And btw: that thread you pointed to has nothing to do with the price of rice in china, nor the question... Yes, I read it... Thank you for taking the time, I appreciate it, but myself, like many many others, can do without the attitude, attached to the post or comment... But thank you for taking the time, sincerely. –  Jun 09 '11 at 08:16
  • I wasn't lambasting you. You may want to read up the FAQ of SO too :-/. I had faced a similar issue and it was due to the release method being called in the callback thread. There is nothing wrong in doing network intensive operations in a different thread and finally updating the UI when its done. You want a perform a async operation without affecting the performance. Probably you should look into apple documentation for the same. http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html#//apple_ref/doc/uid/TP40004591 – Praveen S Jun 09 '11 at 09:13
  • Praveen, thank you for taking the time. I guess I can probably lose the sarcasm in my comments. Nothing against you, But I think it is more common than not, on these types of forums, for those people attempting to answer questions, to come out of now-where with, "you need to read this or that", or "check out the documentation," or even, "sounds you don't know what you're talking about." I have NO tolerance for it... None at all... People just need to realize, they have no idea, who they are talking to... Respect, goes both ways. –  Jun 10 '11 at 06:44
  • 1
    Well i just hope i was not talking to Donald Knuth here!! :-) – Praveen S Jun 10 '11 at 07:48

1 Answers1

29

Ok, The answer (Has nothing at all to do with Curl or some fictional notification to the main thread)

Anyone who gets this error, Don't think WEB Thread or Main Thread, THINK, UITextView or UIScrollView or any other view that might be getting passed off to your new thread.

My problem was a UITextView.text, that was being passed as an argument to the NEW thread... Hence "_WebThreadLockFromAnyThread(bool)"

So a simple fix was to copy it to a local NSString and pass that copy in the argument, to the new thread (I.E... Warning: UIKit should not be called from a secondary thread)

[NSThread detachNewThreadSelector: @selector(sendStuff:) toTarget: self withObject: self.textField.text];

When you see hoof prints, THINK horses, NOT Zebra's.

Community
  • 1
  • 1
  • Nice answer! Warning doesn't seem to suggest this as a problem. You may want to write your analysis (for the sake of others). – Praveen S Jun 10 '11 at 07:47
  • 1
    thanks for this - UIKit should have pointed me to the fact that I was accessing my searchBar.text in a background thread. – Slee Sep 26 '12 at 11:52