     
     private class SerialContext : ExecutionContextBase, ExecutionContextType {
         private let rl:CFRunLoop!
-        private let ownRunLoop:Bool
+        private let finalizer: RunLoopFinalizer?
 
         #if !os(Linux)
         private static let defaultMode:CFString = "kCFRunLoopDefaultMode" as NSString

            thread.start()
        }
        
        func sync<ReturnType>(task:() throws -> ReturnType) throws -> ReturnType {
            return try syncThroughAsync(task)
        }

            pthread_create(thread, nil, thread_proc, UnsafeMutablePointer<Void>(Unmanaged.passRetained(self).toOpaque()))
        }
    }
    
    
    private class RunLoopFinalizer {
        private let rl: CFRunLoop!
        init(_ runLoop: CFRunLoop!) {
            self.rl = runLoop
        }
        deinit {
            CFRunLoopStop(rl)
        }
    }
    
    private class RunLoopObject {
        private var cfObject:AnyObject? = nil
        private let task:SafeTask
        private let finalizer:RunLoopFinalizer?
        
        init(_ task:SafeTask, runLoopFinalizer: RunLoopFinalizer?) {
            self.task = task
            self.finalizer = runLoopFinalizer
        }
        
        func addToRunLoop(runLoop:CFRunLoop, mode: CFString) {
            if cfObject == nil {
                self.cfObject = createCFObject()
            }
            addCFObject(runLoop, mode: mode)
        }
        
        func signal() {}

        private func createCFObject() -> AnyObject? { return nil }
        
        private func addCFObject(runLoop:CFRunLoop, mode: CFString) {}
    }

    private func sourceMain(rls: UnsafeMutablePointer<Void>) {
        let runLoopSource = Unmanaged<RunLoopObject>.fromOpaque(COpaquePointer(rls)).takeUnretainedValue()
        runLoopSource.cfObject = nil
        runLoopSource.task()
    }

    private func sourceCancel(rls: UnsafeMutablePointer<Void>, rL: CFRunLoop!, mode:CFString!) {
        let runLoopSource = Unmanaged<RunLoopObject>.fromOpaque(COpaquePointer(rls)).takeUnretainedValue()
        runLoopSource.cfObject = nil
    }

    private func sourceRetain(rls: UnsafePointer<Void>) -> UnsafePointer<Void> {
        Unmanaged<RunLoopObject>.fromOpaque(COpaquePointer(rls)).retain()
        return rls
    }

    private func sourceRelease(rls: UnsafePointer<Void>) {
        Unmanaged<RunLoopObject>.fromOpaque(COpaquePointer(rls)).release()
    }

    private class RunLoopSource : RunLoopObject {
        private let priority:Int

        init(_ task: SafeTask, priority: Int = 0, finalizer: RunLoopFinalizer?) {
            self.priority = priority
            super.init(task, runLoopFinalizer: finalizer)
        }

        deinit {
            if let s = cfObject as! CFRunLoopSource? {
                if CFRunLoopSourceIsValid(s) { CFRunLoopSourceInvalidate(s) }
            }
        }
        
        private override func createCFObject() -> AnyObject? {
            var context = CFRunLoopSourceContext(
                version: 0,
                info: UnsafeMutablePointer<Void>(Unmanaged.passUnretained(self).toOpaque()),
                retain: sourceRetain,
                release: sourceRelease,
                copyDescription: nil,
                equal: nil,
                hash: nil,
                schedule: nil,
                cancel: sourceCancel,
                perform: sourceMain
            )
            return CFRunLoopSourceCreate(nil, priority, &context)
        }
        
        private override func addCFObject(runLoop:CFRunLoop, mode: CFString) {
            CFRunLoopAddSource(runLoop, (cfObject as! CFRunLoopSource?)!, mode)
        }
        
        override func signal() {
            if let s = cfObject as! CFRunLoopSource? {
                CFRunLoopSourceSignal(s)
            }
        }
    }
    
    private func timerCallback(timer: CFRunLoopTimer!, rlt: UnsafeMutablePointer<Void>) {
        sourceMain(rlt)
    }
    
    private class RunLoopDelay : RunLoopObject {
        private let delay:CFTimeInterval
        
        init(_ task: SafeTask, delay: CFTimeInterval, finalizer: RunLoopFinalizer?) {
            self.delay = delay
            super.init(task, runLoopFinalizer: finalizer)
        }
        
        deinit {
            if let t = cfObject as! CFRunLoopTimer? {
                if CFRunLoopTimerIsValid(t) { CFRunLoopTimerInvalidate(t) }
            }
        }
        
        private override func createCFObject() -> AnyObject? {
            var context = CFRunLoopTimerContext(
                version: 0,
                info: UnsafeMutablePointer<Void>(Unmanaged.passUnretained(self).toOpaque()),
                retain: sourceRetain,
                release: sourceRelease,
                copyDescription: nil
            )
            return CFRunLoopTimerCreate(nil, CFAbsoluteTimeGetCurrent()+delay, -1, 0, 0, timerCallback, &context)
        }
        
        private override func addCFObject(runLoop:CFRunLoop, mode: CFString) {
            CFRunLoopAddTimer(runLoop, (cfObject as! CFRunLoopTimer?)!, mode)
        }
    }
    
