Re: multi-threading, AppKit etc
Re: multi-threading, AppKit etc
- Subject: Re: multi-threading, AppKit etc
- From: Shawn Erickson <email@hidden>
- Date: Mon, 16 Oct 2006 09:46:12 -0700
On Oct 16, 2006, at 9:25 AM, 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
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);
}
1) ...you have me confused... "NSApplicationMain" is a function
provided by the AppKit Framework but in the above you appear to be
implementing your own? Can you explain what is taking place.
2) No need to use your DeadThread object, just remove it from your code.
3) In the above code example you are not getting AppKit/Cocoa
initialized and connected with the window server (assuming the real
NSApplicationMain isn't being called). For this code sample try
adding in NSApplicationLoad(); as the first thing in your main method.
-Shawn
_______________________________________________
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