         }
 
         deinit {
-            if ownRunLoop { CFRunLoopStop(rl) }
-        }
-        
+            if ownRunLoop {
+                let runLoop = rl
+                performRunLoopSource(RunLoopSource({
+                        CFRunLoopStop(runLoop)
+                    },
+                    priority: -32768)
+                )
+            }
+        }
+        
+        #if !os(Linux)
+        static func defaultLoop() {
+            while CFRunLoopRunInMode(defaultMode, 0, true) != .Stopped {}
+        }
+        #else
         static func defaultLoop() {
             while CFRunLoopRunInMode(defaultMode, 0, true) != Int32(kCFRunLoopRunStopped) {}
         }
+        #endif
 
         private func performRunLoopSource(rls: RunLoopSource) {
             rls.addToRunLoop(rl, mode: SerialContext.defaultMode)

                    cancel: sourceCancel,
                    perform: sourceMain
                )
                self.cfSource = CFRunLoopSourceCreate(nil, 0, &context)
            }
            
            CFRunLoopAddSource(runLoop, cfSource!, mode)

    private class RunLoopSource {
        private var cfSource:CFRunLoopSource? = nil
        private let task:SafeTask
        private let priority:Int

        init(_ task: SafeTask, priority: Int = 0) {
            self.task = task
            self.priority = priority
        }

        deinit {
