Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code hangs #8

Closed
salmanlodhi opened this issue Sep 19, 2012 · 14 comments
Closed

code hangs #8

salmanlodhi opened this issue Sep 19, 2012 · 14 comments

Comments

@salmanlodhi
Copy link

I created a new project for your code. Its working fine on simulator.

As soon as i test on IPhone4S .... Program hangs during execution of below code

static LARSAdController *_sharedManager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedManager = [[super allocWithZone:NULL] init];
});

So somehow when its creating the manger in the block..... its delayed or kind of stuck ..... Any idea what is missing ???

@salmanlodhi
Copy link
Author

When I paused the execution in Xcode.... program is stuck on this piece of Apple provided code


void
dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);

DISPATCH_INLINE DISPATCH_ALWAYS_INLINE DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
void
_dispatch_once(dispatch_once_t _predicate, dispatch_block_t block)
{
if (DISPATCH_EXPECT(_predicate, ~0l) != ~0l) {
dispatch_once(predicate, block);
}
}


..... exactly on dispatch_once(predicate, block); function

@larsacus
Copy link
Owner

That's a pretty basic couple of lines of code. If it's hanging anywhere it is in the allocWithZone: method of the superclass, which is simply an NSObject. So there's really not much that can fail here, unless you have your project setup incorrectly with regards to ARC/Non-ARC.

@salmanlodhi
Copy link
Author

ARC is disabled....

only missing thing was the compiler flag for LARSadcontroller.m .. I even added that ..... but still same issue

This code works fine on simulator but only hangs on iPhone ....

@salmanlodhi
Copy link
Author

Now I created a new project and its getting stuck on same line with Simulator and Device :(

@larsacus
Copy link
Owner

It's your environment. There is nothing wrong with the code you're talking about. I can say that with confidence because the section in question that it's "hanging" on is all Foundation code and not my own. Try cleaning your build, deleting the app from both the simulator and the device, close Xcode, and restart your computer.

Also, try running the sample project included with the source code.

@salmanlodhi
Copy link
Author

Okie..its all happening due to threading...if i remove this dispatch_once thing then it works fine...only thing is that it keeps loading again and again

@larsacus
Copy link
Owner

That's because dispatch_once is the singleton initializer that guarantees that the system will only call it once and it will be a no-op on subsequent calls

@salmanlodhi
Copy link
Author

How about i use some global variable value to determine ... if it needs to be instantiated ?

@larsacus
Copy link
Owner

That's exactly what static dispatch_once_t onceToken; is doing. After the token is set on the first execution (thus why you are passing it in by reference to dispatch_once with &onceToken), dispatch_once does not fire what is in it's block. Are you calling these methods from a thread other than the main thread?

This code is running fine on tens of thousands of devices in production.

@salmanlodhi
Copy link
Author

I know your code is fine..... it works in other project made by me

I am calling this code in view will appear of the first View Controller that the app loads .... i created a new project .... with only one view controller then it worked fine.... now as soon as i included my other view controllers (already written previously)........ same behavior is returned....

@larsacus
Copy link
Owner

Not sure what to say without seeing the project.

@salmanlodhi
Copy link
Author

could this be possible reason

"dispatch_once will deadlock if the something in the -init method calls the +singleton method. "

source : http://cocoasamurai.blogspot.com/2011/04/singletons-your-doing-them-wrong.html

@salmanlodhi
Copy link
Author

wait a minute .... i just checked that i load data from files in my app delegate.... in function didFinishLaunchingWithOptions

if i remove data load function then ads are displayed......

@salmanlodhi
Copy link
Author

I created a global variable which i initialize in didFinishLaunchingWithOptions function in delegate......

In rest of code in just refer to this variable which is of type LARSAdController.

Problem Solved :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants