All pastes #802804 Raw Edit

Mine

public text v1 · immutable
#802804 ·published 2007-11-30 17:41 UTC
rendered paste body
static NSMapTable *pThreadMessagePorts = NULL;

@implementation InterThreadManager

+ (void) initialize {
	pThreadMessagePorts = NSCreateMapTable(...);
}

@end



@implementation NSThread (InterThreadMessaging)

+ (void) prepareForInterThreadMessages
{
    /* Force the class initialization. */
    [InterThreadManager class];

    createMessagePortForThread([NSThread currentThread], [NSRunLoop currentRunLoop]);
}

@end



static void
createMessagePortForThread (NSThread *thread, NSRunLoop *runLoop)
{
    assert(NULL != pThreadMessagePorts);   //  This very, very occasionally fails.  Does making pThreadMessagePorts volatile fix it?
}