]> git.cworth.org Git - apitrace/commitdiff
Force Cocoa to enter multithreaded mode.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 24 Oct 2012 12:57:02 +0000 (13:57 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 24 Oct 2012 13:02:53 +0000 (14:02 +0100)
retrace/glws_cocoa.mm

index df7dd84018171b298532021200595903b31d40a5..e410862f1996aa278d64db22c2ec3ba4eac81694 100644 (file)
@@ -33,6 +33,8 @@
  * - http://developer.apple.com/library/mac/#samplecode/glut/Introduction/Intro.html
  * - http://developer.apple.com/library/mac/#samplecode/GLEssentials/Introduction/Intro.html
  * - http://www.glfw.org/
+ * - http://cocoasamurai.blogspot.co.uk/2008/04/guide-to-threading-on-leopard.html
+ * - http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html
  */
 
 
 #include "glws.hpp"
 
 
+/**
+ * Dummy thread to force Cocoa to enter multithreading mode.
+ */
+@interface DummyThread : NSObject
+    + (void)enterMultiThreaded;
+    + (void)dummyThreadMethod:(id)unused;
+@end
+
+@implementation DummyThread
+    + (void)dummyThreadMethod:(id)unused {
+        (void)unused;
+    }
+
+    + (void)enterMultiThreaded {
+        [NSThread detachNewThreadSelector:@selector(dummyThreadMethod:)
+                  toTarget:self
+                  withObject:nil];
+    }
+@end
+
+
 namespace glws {
 
 
@@ -174,6 +197,14 @@ init(void) {
 
     initThread();
 
+    [DummyThread enterMultiThreaded];
+
+    bool isMultiThreaded = [NSThread isMultiThreaded];
+    if (!isMultiThreaded) {
+        std::cerr << "error: failed to enable Cocoa multi-threading\n";
+       exit(1);
+    }
+
     [NSApplication sharedApplication];
 
     [NSApp finishLaunching];