Author: Chris Lattner
The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).
My take-aways are:
-
You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.
-
Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse
Foundation offers a Thread class, internally based on pthread, that can be used to create new threads and execute closures.
// Detaches a new thread and uses the specified selector as the thread entry point.
Thread.detachNewThreadSelector(selector: Selector>, toTarget: Any, with: Any)
// Subclass
class MyThread: Thread {| // | |
| // SpinlockTestTests.swift | |
| // SpinlockTestTests | |
| // | |
| // Created by Peter Steinberger on 04/10/2016. | |
| // Copyright © 2016 PSPDFKit GmbH. All rights reserved. | |
| // | |
| import XCTest |
| name | download_total | |
|---|---|---|
| AFNetworking | 61983241 | |
| Fabric | 50998892 | |
| Crashlytics | 49667729 | |
| SDWebImage | 45471101 | |
| Alamofire | 42097177 | |
| CocoaLumberjack | 36071914 | |
| Bolts | 35294870 | |
| FirebaseInstanceID | 30277793 | |
| FirebaseAnalytics | 30254593 |
| #!/bin/bash | |
| # | |
| # Credits to fuckbecauseican5 from https://www.reddit.com/r/hackintosh/comments/4s561a/macos_sierra_16a238m_install_success_and_guide/ | |
| # Adapted to work with the official image available into Mac App Store | |
| # | |
| # Enjoy! | |
| hdiutil attach /Applications/Install\ macOS\ Sierra.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app | |
| hdiutil create -o /tmp/Sierra.cdr -size 7316m -layout SPUD -fs HFS+J | |
| hdiutil attach /tmp/Sierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build |
| /** | |
| * Several macros simplifying use of weak references to self inside blocks | |
| * which goal is to reduce risk of retain cycles. | |
| * | |
| * Example: | |
| * @code | |
| @interface Example : NSObject{ | |
| int _i; | |
| } |