Time Travel - Predicting the Future and Surviving a Parallel Universe - JDC2012

Embed Size (px)

DESCRIPTION

 

Citation preview

  • 1. Time Travel!Predicting the Future !and Surviving a Parallel Universe ! Hossam Karim!
  • 2. The Free Lunch is Over!!
  • 3. Welcome to the Real World!
  • 4. Concurrency!
  • 5. Its Pretty Hard!
  • 6. Concurrency Pain!
  • 7. Doubled-Checked Locking Problem!"#$%&!&$((!"#$%&()*+,-#*+./0!1!!!!!!!)%*+,!234/5.675#$8*!34/5.675#$8*9!!!!!!!"#$%&!234/5.675#$8*!0:234/5.675#$*;!!!!>!
  • 8. Doubled-Checked Locking Problem!"#$%&!&$((!"#$%&()*+,-#*+./0!1!!!!!!!)%*+,!234/5.675#$8*!34/5.675#$8*9!!!!!!!"#$%&!234/5.675#$8*!0:234/5.675#$*;&$((
  • 9. Doubled-Checked Locking Problem!"#$%&!&$((!"#$%&()*+,-#*+./0!1!!!!!!!)%*+,!234/5.675#$8*!34/5.675#$8*9!!!!!!!"#$%&!234/5.675#$8*!0:234/5.675#$*;&$((
  • 10. Doubled-Checked Locking Problem volatileThread AThread B Processor Main Cache Memory synchronized
  • 11. Doubled-Checked Locking Problem!"#$%&!&$((!"#$%&()*+,-#*+./0!1!!!!)%*+,!*-$+%$,!234/5.675#$8*!34/5.675#$8*9!!!!!!!"#$%&!234/5.675#$8*!0:234/5.675#$*;&$((
  • 12. Scala!"#$$!"#$%$&(()*+,%(-.(#/(01*#/234!5!!!!!!!!"#%&!#"!(67(3829(:(8*+#(!;!()*!4*%#%#87(%G/"0.(!!!!!!2!!!!!!!!(H5%8*,!-#".!!!!!!!!!!!!#!(-#";#$F#*5%8*G.!H5%8*!+I!-#"!"/1"!H5%8*!!!!!!J!!!!!!,!%G/"0.!2!!!!!!!!(H5%8*,!)#*.!!!H5%8*!II!"#$%"$()#*,!-#"%*.!!!!!!J!!!!J!
  • 26. Scala Parallel Collections!!!"#$%&()!!!!!"#!&%*#+%&(*,()-!!!!!!$)).!$"%&(/+%&(01!2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*4*5#)*+,;+,3??$#12()*+,"76*$?@6,?:&.#*()*+,!./,(0!!!!!!!!!!&+.512B+369!!!!!!!!#$%!+*C,!!!!!!!!!!!!!!&+.512B+3
  • 33. Akka Actors!!!"#$$!"#$#%()*+!%&%()$!!"#$%!,!!!!*#"!$*%!-!.*%%/0%1)*0#23454#67!+,$8!!!!!!)%-!+#)#/9#!-!,!!!!!!!!!#$%!:&6;$#?#)#/9#@!6#44&%#!A4>3=*+6&16#44&%#88!!!!!!B!!B!!!!
  • 34. Akka Futures ./0$1-$2&!"#$%&3)*4,$5 !"#$%&+",*$- !"#$%&3)*4,$&./0$1-"-)6(%!"#$%"(()(* 76(%4#-"(18&9$:4$%- 9$16;;$(2"-)6(% 3)("(1)"# 76(%4#-"(-%
  • 35. Akka Futures ! !!"#!"#$#%&$%($&)*&+,!!"#"$%-&(#-$%($&).&/&0$*1233!4! !!!$%&!5! %"#$%+",*$-./-0, !!!!!(/&+6*)#%&78(/#&9!:!! !!!!!!!7+(/&+;(%)&$&?#&+$7()!@($&99AB(C;1-(/&+6*)#%&3! !!!!!!!!!+$%($&)*&+!:!! !!!!!!!!!!!6#$#%&A$%(8&%+&7012+#/$(20.&?#&+$78(/#&99AB(C;1-$%($&).&/&0$*1239! !"#$%1)*2,$3$42$%- !!!D!*+(#,!+$%($&)*&+! !! !"#$%1)*2,$ -!"#!"#$#%&>&01BB&2E($*12+,!!"#"$%-&(#-)#$*#%+,33!4! !!!"#$#%&$%($&)*&+AB(C7! !!!!!/*+$F"$%($&).&/&0$*12!!" """"""""""""""""/*+$F"$%($&).&/&0$*12A"/($G(C7HA%&01BB&2E($*12+99! !! !"#$%"(()(* !-,"-$*53$42$%- !3$/066$(7"-)0(% /0(%2#-"(/5./-0, /0(%2#-"(/5./-0, /0(%2#-"(/5./-0,
  • 36. Akka Futures!!!"#!"#$#%&$%($&)*&+,!!"#"$%-&(#-$%($&).&/&0$*1233!4!!!!$%&!5!!!!!!!(/&+6*)#%&78(/#&9!:!!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 39. Relations to Functional Programming!Selected Topics
  • 40. Monoid !"#$%&() !*%%$+,-.,/,.0) !12(3.,.0)!"#$#%&((!)#*#+& !"#$#%#)#*#+&,!"#$&((!%#)&-((!*#+& !"#$#%#)#*#+&!"#$&((,!%#)&((!*#+&-!"#$#%&((!& !"#$#%&!&((!"#$#%&
  • 41. Monoid !"#"$%&()*%+,-.+.//%/0 1%+2%
  • 42. Immutable Data Structures Googles Guava!!!"#$%&!!"#$"#$%&()!&**+$,-./01../2$&1345!6!!!!!!!"#$"#$%&()!3$%&(3!7!!!!!!!!%&&$()*+!"#$8"#$%&())"*,+-458!!!!!!!!!!,994:;11(./+&.9/%3:58!!!!!!!!!!-+&.945?!!!!!!..#$-"/0#1(,,2345$675##")*+389!!!!!!()"*!3$%&(3?!!!!@!!! h.p://code.google.com/p/memory-measurer/wiki/ElementCostInDataStructures ! Immutable Data Structures Scala!!!"#!"#$%$&()$*%+,-")!.!!!!/0#$%$/!11!/&()$*%+/!11!/,-")/!11!2-%!!!! h.p://en.wikipedia.org/wiki/Persistent_data_structure
  • 43. Persistent Data Structures ! % & !!"#!"#$%$&()$*+!,!-.-!//!-0-!//!-1-!//!-2-!//!3$(! !!!!!! !!"#!4)$*+!,!-5-!//!"#$%$&()$*+! !!! !!"#!6)$*+!,!"#$%$&()$*+!$"%&!7! !!!!&"()!89:!//!+$(!!!-;-!//!+$(!" !!!!&"()!)$*+!,!"#$%$&()$*+!$"%&!7! !!!!&"()!?$#*+!//!*9@"&:!//!+$(!!!-A-!//!+$(! !!!!&"()!
  • 44. Thank You!