0001    /*
0002    * Dispatch (dispatch.swift) - Please be Safe
0003    *
0004    * Copyright (C) 2015 ONcast, LLC. All Rights Reserved.
0005    * Created by Josh Baker (joshbaker77@gmail.com)
0006    *
0007    * This software may be modified and distributed under the terms
0008    * of the MIT license.  See the LICENSE file for details.
0009    *
0010    * Portions of the documentation of this code are reproduced from
0011    * work created and shared by Google and used according to terms
0012    * described in the Creative Commons 3.0 Attribution License.
0013    *
0014    * http://golang.org/ref/spec
0015    */
0016    
0017    #if os(Linux)
0018    import Glibc
0019    #endif
0020    
0021    import Foundation
0022    
0023    private let pt_entry
dispatch.swift:36
    pthread_create(&t, nil, pt_entry, p)
: @convention(c) (UnsafeMutablePointer<Void>) -> UnsafeMutablePointer<Void> = { (ctx) in 0024 let np = UnsafeMutablePointer<()->()>(ctx) 0025 np.memory() 0026 np.destroy() 0027 np.dealloc(1) 0028 return nil 0029 } 0030 0031 /// A `dispatch` statement starts the execution of an action as an independent concurrent thread of control within the same address space. 0032 public func dispatch(action: ()->()){ 0033 let p = UnsafeMutablePointer<()->()>.alloc(1) 0034 p.initialize(action) 0035 var t = pthread_t() 0036 pthread_create(&t, nil, pt_entry, p) 0037 pthread_detach(t) 0038 } 0039 0040 0041 0042