Skip to content

Instantly share code, notes, and snippets.

@chadaustin
Created August 10, 2016 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadaustin/2a05224e0f3442960359797b74b27aab to your computer and use it in GitHub Desktop.
Save chadaustin/2a05224e0f3442960359797b74b27aab to your computer and use it in GitHub Desktop.
//
// main.swift
// memsafe
//
// Created by Chad Austin on 8/10/16.
// Copyright © 2016 Chad Austin. All rights reserved.
//
import Foundation
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
let queue = dispatch_get_global_queue(priority, 0)
class Bird {
init(n: Int) {
self.n = n
}
private let n: Int
}
enum Variant {
case V1(Bird)
case V2(Double)
}
var single = Variant.V2(5)
dispatch_async(queue) {
while true {
switch single {
case .V1(let b):
print(b.n)
case .V2(let n):
print(n)
}
}
}
while true {
if drand48() < 0.5 {
single = .V1(Bird(n: 15))
} else {
single = .V2(1.0 / 3.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment