From c94ef353dd2a8392ec5dbbfe1d345945acde7d20 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 24 Oct 2012 13:57:02 +0100 Subject: [PATCH] Force Cocoa to enter multithreaded mode. --- retrace/glws_cocoa.mm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/retrace/glws_cocoa.mm b/retrace/glws_cocoa.mm index df7dd84..e410862 100644 --- a/retrace/glws_cocoa.mm +++ b/retrace/glws_cocoa.mm @@ -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 */ @@ -48,6 +50,27 @@ #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]; -- 2.43.0