2013-05-15 threads. why and how

263 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
263
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

2013-05-15 threads. why and how

  1. 1. Why we should use thread and how to do itwith no additional efforts.
  2. 2.  Dominik Haska – Research SoftwareDeveloper in Jeppesen a Boeing Company 9 years of professional programmingincluding 1 year in IOS
  3. 3.  Why◦ Moore law and physics limitations How◦ how to use the potentially power of multicoredevices easily and properly
  4. 4.  iPhone 1 – 1 CPU 412 MHz iPhone 5 – 2 CPU 1300 MHz iPad 1 – 1 CPU 1000 MHz iPad 4 (retina) – 2 CPU 1400 MHz
  5. 5.  all animations:◦ GPU is a massive multiprocessor unit◦ Just use the animation block[UIView animateWithDuration:1.0 animations:^{firstView.alpha = 0.0;secondView.alpha = 1.0;}];
  6. 6. [UIView beginAnimations:@"ToggleViews" context:nil];[UIView setAnimationDuration:1.0];// Make the animatable changes.firstView.alpha = 0.0;secondView.alpha = 1.0;// Commit the changes and perform the animation.[UIView commitAnimations];
  7. 7.  Animation block stops user interaction duringanimation animateWithDuration:delay: options:animations:completion: UIViewAnimationOptions:◦ UIViewAnimationOptionAllowUserInteraction◦ UIViewAnimationOptionBeginFromCurrentState [self.layer removeAllAnimations];
  8. 8.  CGRect animatedFrame =[self.animatedView.layer.presentationLayerframe]; CGRect targetFrame = self. animatedView.frame; if(animatedFrame.origin.x != 0.0 ||animatedFrame.origin.y != 0.0){CGFloat xMis = animatedFrame.origin.x –targetFrame.origin.x;CGFloat yMis = animatedFrame.origin.y -targetFrame.origin.y;[fix the position];}
  9. 9.  Create property with quee◦ [NSOperationQueue new]; Create invocation◦ NSInvocationOperation *operation =[[NSInvocationOperation alloc] initWithTarget:selfselector:@selector(calculate) object:nil]; Add operation to quee◦ [self.renderingQueue addOperation:operation]; Or remove (cancelAllOperations)
  10. 10.  Some code have to be executed in mainthread◦ [NSString sizeWithFont] – sometimes – onceper 1-2 day crashes app◦ [[UIView alloc] init]◦ [view addSubview…] Solution◦ Delegate and perform on main threadperformSelectorOnMainThread:@selector(◦ Use NSAttributedString to work with UIKit Additions◦ Always check when app crashes in which thread areyou
  11. 11.  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT),^{your code here}
  12. 12.  Long time for response Multiple resources needed in parraler(webbrowsers) Ready to use in ios: [SSLConnectionsendAsynchronousRequest:requestqueue:[NSOperationQueue mainQueue]completionHandler:^(NSURLResponse*response, NSData* data, NSError*error){ … }
  13. 13.  You have multicore devices – use this Look for simplest solution – use library asmuch as possible Focus on user interaction – do not freeze yourapps Be carefull with debugging – single threadapp is much more testable – much muchmore I work for jeppesen boeing company – if ishow you sample code I have to kill you ;) –but next time I try to be better
  14. 14.  developer.apple.com http://www.gotw.ca/publications/concurrency-ddj.htm - the free lunch is over http://www.robotswillstealyourjob.com/ -robots are stealing your job – and engineershelp them to http://www.extremetech.com/computing/116561-the-death-of-cpu-scaling-from-one-core-to-many-and-why-were-still-stuck/2

×