Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -20,10 +20,14 @@ # include # include #else # include #endif + +#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) +# import +#endif #import "OFThread.h" #import "OFList.h" #import "OFDate.h" #import "OFAutoreleasePool.h" @@ -49,10 +53,14 @@ static of_tlskey_t thread_self; static id call_main(id obj) { +#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) + objc_thread_add(); +#endif + if (!of_tlskey_set(thread_self, obj)) @throw [OFInitializationFailedException newWithClass: [obj class]]; /* @@ -67,10 +75,14 @@ [OFTLSKey callAllDestructors]; [OFAutoreleasePool releaseAll]; [obj release]; + +#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) + objc_thread_remove(); +#endif return 0; } @implementation OFThread @@ -206,10 +218,14 @@ [OFTLSKey callAllDestructors]; [OFAutoreleasePool releaseAll]; [thread release]; + +#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) + objc_thread_remove(); +#endif of_thread_exit(); } - initWithObject: (id)obj @@ -241,10 +257,15 @@ - (void)start { if (running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException newWithClass: isa thread: self]; + + if (running == OF_THREAD_WAITING_FOR_JOIN) { + of_thread_detach(thread); + [retval release]; + } [self retain]; if (!of_thread_new(&thread, call_main, self)) { [self release]; @@ -270,10 +291,17 @@ { if (running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException newWithClass: isa thread: self]; + /* + * We should not be running anymore, but call detach in order to free + * the resources. + */ + if (running == OF_THREAD_WAITING_FOR_JOIN) + of_thread_detach(thread); + [object release]; [retval release]; [super dealloc]; } Index: src/threading.h ================================================================== --- src/threading.h +++ src/threading.h @@ -88,10 +88,21 @@ CloseHandle(thread); return YES; #endif } + +static OF_INLINE BOOL +of_thread_detach(of_thread_t thread) +{ +#if defined(OF_HAVE_PTHREADS) + return !pthread_detach(thread); +#elif defined(_WIN32) + /* FIXME */ + return YES; +#endif +} static OF_INLINE void of_thread_exit() { #if defined(OF_HAVE_PTHREADS)