Skip to content

Instantly share code, notes, and snippets.

@mdales
Last active August 31, 2022 18:28
Show Gist options
  • Save mdales/68e2345f7be3d71377a29904d07643f8 to your computer and use it in GitHub Desktop.
Save mdales/68e2345f7be3d71377a29904d07643f8 to your computer and use it in GitHub Desktop.
import Dispatch
import Foundation
let syncQ = DispatchQueue(label: "sync")
var count = 0
let q = DispatchQueue(label: "test")
func test() {
syncQ.sync {
print("hello \(count)")
}
q.asyncAfter(deadline: .now() + 1.0, execute: test)
}
q.asyncAfter(deadline: .now() + 1.0, execute: test)
public func registerSighup() -> DispatchSourceSignal {
signal(SIGHUP, SIG_IGN)
let sigintSrc = DispatchSource.makeSignalSource(signal: SIGHUP, queue: syncQ)
sigintSrc.setEventHandler {
count += 1
}
sigintSrc.resume()
return sigintSrc
}
let source = registerSighup()
dispatchMain()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment