Re: multi-threading, AppKit etc
Re: multi-threading, AppKit etc
- Subject: Re: multi-threading, AppKit etc
- From: Apparao <email@hidden>
- Date: Tue, 17 Oct 2006 15:16:15 +0530
[NSThread detachNewThreadSelector:@selector(emptyThreadMethod:)
toTarget:[DeadThread class] withObject: nil]; // force Cocoa to
enter multithreading mode.
In detachNewThreadSelector, toTarget: expects id argument, not class
structure.
On 16-Oct-06, at 9:55 PM, Tom O'Grady wrote:
hi there,
i'm having a bit of trouble with the following test code i wrote
(debugger exits at the runModal: method of NSAlert even though it's
called in the main thread):
(i'm afraid it's missing all the includes/imports).
my project required a 'main' so i call the NSApplicationMain from
that - i'm hoping that's not what's causing the problem, since the
test confirms that the NSAlert is in the main thread.
any help would be much appreciated,
thanks,
tom
@interface DeadThread : NSThread {;;}
+ (void)enterMultiThreadedMode;
+ (void)emptyThreadMethod:(id)obj;
@end
@implementation DeadThread
+ (void)enterMultiThreadedMode
{
[NSThread detachNewThreadSelector:@selector(emptyThreadMethod:)
toTarget:[DeadThread class] withObject: nil]; // force Cocoa to
enter multithreading mode.
}
+ (void)emptyThreadMethod:(id)obj {;;}
@end
int NSApplicationMain(int argc, const char ** argv)
{
[DeadThread enterMultiThreadedMode];
bool multi = [NSThread isMultiThreaded]; // currently returns
TRUE, confirming that Cocoa is in multithreading mode.
NSAutoreleasePool releasePool;
const unistring mess = "error message"; // a unistring is just a
typedef'd std::string that our company uses.
const unistring title = "new error";
NSString *message = [[NSString alloc] initWithCString:title.c_str
() encoding:NSASCIIStringEncoding];
NSString *information = [[NSString alloc]
initWithCString:mess.c_str() encoding:NSASCIIStringEncoding];
NSAlert *alertbox = [[NSAlert alloc] init];
[alertbox setMessageText:message];
[alertbox setInformativeText:information];
[alertbox setAlertStyle:NSCriticalAlertStyle];
[alertbox addButtonWithTitle:@"OK"];
int test = pthread_main_np(); // currently returns a value of '1',
confirming that the NSAlert instance is being run in the main
thread as required (AppKit stuff still cannot assumed to be
threadsafe otherwise?)
return [alertbox runModal];
}
int main(int argc, char* argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40effigent.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden