bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

run NSApllication in an other thread


From: Julien Isorce
Subject: run NSApllication in an other thread
Date: Tue, 17 Feb 2009 21:36:09 +0100

Hi,

I can read in NSApplication's documentation that it must be called in the main thread.

I am in a case where there is an other main loop (in C) that I cannot managed.
The code I can access is an interface and its implementation that leads to a shared library loaded by the main application where there is this C main loop.
Well, in the implementation (that I have to make) threre is 3 functions.
One for initialization, one for deinitialization, and the last one is called periodically.
In the init function I create an NSWindow. Then this window has to be updated in the function called periodically.

In no cocoa env I usually create a thread in the init function. This thread runs the specific window main loop (X loop or gdi32 loop). And it works pretty good.
I want to do the same thing in a cocoa env. I mean, i would like to run the cocoa main loop in a thread created in the init function.

Even if I read that NSApplicationMain (or [NSApp run] ) must be called in the main thread, I  tried to call it in a different thread.
But I am getting an acces violation in the main thread.
Then if a replace the [NSApp run] from the second thread, by a while an a sleep,  I have an access violation in the main thread only I do not call [NSApp run] in the main thread.
(but I cannot call [NSApp run] in the main thread because the function must be called periodically, I must not block the main thread)

I am creating the thread with:

 [NSThread detachNewThreadSelector: @selector(start:)
        toTarget: [AppThread class]
        withObject: nil];

(like I could see in the gnu step examples)

I am still on win32.

Any suggestion ?

Sincerely

Julien



reply via email to

[Prev in Thread] Current Thread [Next in Thread]