setObjectForKey = sel_registerName ("setObject:forKey:");
objectForKey = sel_registerName ("objectForKey:");
- // define the dead letter class
- mono_dead_letter_class = objc_allocateClassPair (nsobject, "MonoDeadLetter", 0);
+ char *class_name = g_strdup_printf ("MonoDeadLetter%p", &"MonoDeadLetter");
+
+ // Define the dead letter class
+ // The class name needs to be unique in the event different runtimes are loaded into the same process.
+ mono_dead_letter_class = objc_allocateClassPair (nsobject, class_name, 0);
+ g_free (class_name);
+
class_addMethod (mono_dead_letter_class, dealloc, (IMP)mono_dead_letter_dealloc, "v@:");
objc_registerClassPair (mono_dead_letter_class);
#include "pal_autoreleasepool.h"
#include <Foundation/Foundation.h>
-
-@interface PlaceholderObject : NSObject
-- (void)noop:(id)_;
-@end
-
-@implementation PlaceholderObject : NSObject
-- (void)noop:(id)_
-{
- [self release];
-}
-@end
+#include <objc/runtime.h>
void EnsureNSThreadIsMultiThreaded(void)
{
// Start another no-op thread with the NSThread APIs to get NSThread into multithreaded mode.
// The NSAutoReleasePool APIs can't be used on secondary threads until NSThread is in multithreaded mode.
// See https://developer.apple.com/documentation/foundation/nsautoreleasepool for more information.
- PlaceholderObject* placeholderObject = [[PlaceholderObject alloc] init];
-
+ //
// We need to use detachNewThreadSelector to put NSThread into multithreaded mode.
// We can't use detachNewThreadWithBlock since it doesn't change NSThread into multithreaded mode for some reason.
// See https://developer.apple.com/documentation/foundation/nswillbecomemultithreadednotification for more information.
- [NSThread detachNewThreadSelector:@selector(noop:) toTarget:placeholderObject withObject:nil];
+ id placeholderObject = [[NSMutableString alloc] init];
+ [NSThread detachNewThreadSelector:@selector(appendString:) toTarget:placeholderObject withObject:@""];
+ [placeholderObject release];
}
assert([NSThread isMultiThreaded]);
}