Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Shared Mutable State

Shared Mutable State

How can we deal with the complexities and troubles brought by shared mutable state in our code? Presented at AltConf 2018.

Greg Heo

June 06, 2018
Tweet

More Decks by Greg Heo

Other Decks in Technology

Transcript

  1. @gregheo AltConf, June 2018 queue1.async {
 
 } queue2.async {


    
 
 } 
 stuff()
 
 things()
 things2()

  2. @gregheo AltConf, June 2018 Exclusive Shared Immutable Mutable private let

    private var
 private queue UIDevice
 Screen size &
  3. @gregheo AltConf, June 2018 
 // call from anywhere!
 public

    func something() {
 privateQueue.sync { … } }

  4. @gregheo AltConf, June 2018 
 // always call on the

    main queue!
 public func something() 

  5. @gregheo AltConf, June 2018 
 // always call on the

    main queue!
 public func something() {
 dispatchPrecondition(condition: .onQueue(.main))
 }

  6. @gregheo AltConf, June 2018 # Do I have order right?

    Is the order even knowable? Is it concurrent?