Differences From Artifact [82882ba976]:
- File src/OFThread.m — part of check-in [c7f0229795] at 2020-01-02 01:51:34 on branch trunk — Update copyright (user: js, size: 10652) [annotate] [blame] [check-ins using] [more...]
To Artifact [5a3f2982c0]:
- File
src/OFThread.m
— part of check-in
[e7f4f80e23]
at
2020-01-24 03:03:32
on branch trunk
— runtime: Correctly handle AR pool push during pop
Getting a pointer and increasing it until we reach the top pointer does
not work: Releasing an object can temporarily create new autorelease
pools, which can trigger resizing of "objects" using realloc, which can
move it to a different address, which will then lead to continuing to
iterate on a now invalid pointer.This is now solved by using an index into "objects" instead. Since we're
now indexing for the pop, let's use indexes everywhere, as they're more
readable anyway.While debugging this, I noticed that the last pool is popped quite
frequently, only for a new pool to be pushed immediately again. This
resulted in a free followed by a malloc every time. Instead, keep the
pool, but let OFThread explicitly say when to free everything. (user: js, size: 10770) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | OFThread *thread = (OFThread *)object; OFString *name; if (!of_tlskey_set(threadSelfKey, thread)) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; thread->_pool = objc_autoreleasePoolPush(); name = thread.name; if (name != nil) of_thread_set_name( [name cStringWithEncoding: [OFLocale encoding]]); else of_thread_set_name(object_getClassName(thread)); | > > | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | OFThread *thread = (OFThread *)object; OFString *name; if (!of_tlskey_set(threadSelfKey, thread)) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; #ifndef OF_OBJFW_RUNTIME thread->_pool = objc_autoreleasePoolPush(); #endif name = thread.name; if (name != nil) of_thread_set_name( [name cStringWithEncoding: [OFLocale encoding]]); else of_thread_set_name(object_getClassName(thread)); |
︙ | ︙ | |||
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | else # endif thread->_returnValue = [[thread main] retain]; } [thread handleTermination]; objc_autoreleasePoolPop(thread->_pool); #if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS) if (thread.supportsSockets) of_socket_deinit(); #endif thread->_running = OF_THREAD_WAITING_FOR_JOIN; | > > > > | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | else # endif thread->_returnValue = [[thread main] retain]; } [thread handleTermination]; #ifdef OF_OBJFW_RUNTIME objc_autoreleasePoolPop((void *)(uintptr_t)-1); #else objc_autoreleasePoolPop(thread->_pool); #endif #if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS) if (thread.supportsSockets) of_socket_deinit(); #endif thread->_running = OF_THREAD_WAITING_FOR_JOIN; |
︙ | ︙ |