Skip to content

Instantly share code, notes, and snippets.

let task = Process()
task.launchPath = "/bin/sh" //executable you want to run
task.arguments = arguments //here is the information you want to pass
task.terminationHandler = {
// do here something in case the process terminates
}
task.launch()
class CustomThread: Thread {
override func main() {
do_something
}
}
let customThread = CustomThread()
customThread.start()
DispatchQueue.main.async {
// execute async on main thread
}
let operationQueue: OperationQueue = OperationQueue()
operationQueue.addOperations([operation1], waitUntilFinished: false)
class CustomOperation: Operation {
override func main() {
guard isCancelled == false else {
finish(true)
return
}
// Do something
finish(true)
operation2.addDependency(operation1) //execute operation1 before operation2
let lock = NSLock()
lock.lock()
//do something
lock.unlock()
var m = pthread_mutex_t()
pthread_mutex_lock(&m)
// do something
pthread_mutex_unlock(&m)
let s = DispatchSemaphore(value: 1)
_ = s.wait(timeout: DispatchTime.distantFuture)
// do something
s.signal()
let lock = self
objc_sync_enter(lock)
closure()
objc_sync_exit(lock)