This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomThread: Thread { | |
| override func main() { | |
| do_something | |
| } | |
| } | |
| let customThread = CustomThread() | |
| customThread.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DispatchQueue.main.async { | |
| // execute async on main thread | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let operationQueue: OperationQueue = OperationQueue() | |
| operationQueue.addOperations([operation1], waitUntilFinished: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomOperation: Operation { | |
| override func main() { | |
| guard isCancelled == false else { | |
| finish(true) | |
| return | |
| } | |
| // Do something | |
| finish(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation2.addDependency(operation1) //execute operation1 before operation2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let lock = NSLock() | |
| lock.lock() | |
| //do something | |
| lock.unlock() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var m = pthread_mutex_t() | |
| pthread_mutex_lock(&m) | |
| // do something | |
| pthread_mutex_unlock(&m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let s = DispatchSemaphore(value: 1) | |
| _ = s.wait(timeout: DispatchTime.distantFuture) | |
| // do something | |
| s.signal() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let lock = self | |
| objc_sync_enter(lock) | |
| closure() | |
| objc_sync_exit(lock) |