@@ -238,14 +238,28 @@ if (!of_tlskey_set(threadSelfKey, mainThread)) @throw [OFInitializationFailedException exceptionWithClass: self]; } -- initWithObject: (id)object_ +- init { self = [super init]; + @try { + runLoop = [[OFRunLoop alloc] init]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithObject: (id)object_ +{ + self = [self init]; + object = [object_ retain]; return self; } @@ -257,11 +271,11 @@ } - initWithObject: (id)object_ block: (of_thread_block_t)block_ { - self = [super init]; + self = [self init]; @try { object = [object_ retain]; block = [block_ copy]; } @catch (id e) { @@ -281,12 +295,13 @@ return nil; } - (void)handleTermination { - [runLoop release]; - runLoop = nil; + OFRunLoop *old = runLoop; + runLoop = [[OFRunLoop alloc] init]; + [old release]; } - (void)start { if (running == OF_THREAD_RUNNING) @@ -326,17 +341,10 @@ - (OFRunLoop*)runLoop { return [[runLoop retain] autorelease]; } -- (void)OF_setRunLoop: (OFRunLoop*)runLoop_ -{ - OFRunLoop *old = runLoop; - runLoop = [runLoop_ retain]; - [old release]; -} - - (void)dealloc { if (running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException exceptionWithClass: [self class] @@ -349,10 +357,11 @@ if (running == OF_THREAD_WAITING_FOR_JOIN) of_thread_detach(thread); [object release]; [returnValue release]; + [runLoop release]; [super dealloc]; } - copy