bug-gnustep
[Top][All Lists]
Advanced

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

Re: run NSApllication in an other thread


From: Richard Frith-Macdonald
Subject: Re: run NSApllication in an other thread
Date: Wed, 18 Feb 2009 06:55:11 +0000


On 17 Feb 2009, at 22:38, Julien Isorce wrote:


Unfortunately, I am in a case where I cannot manage the C main loop (I cannot configure it and I cannot start it).
I am implemting a plugin interface which lead to a shared library.
This library is loaded by the main program and I have not access to the code of this main program and so I cannot have access to the code
which runs the C main loop.
It's like the concept of plugins work in some cases. But I am sure my first description was a little bit confusing. In other word I cannot see how the periodic function could be called in an other thread than the main one.

So I still have access to 3 functions, init, periodic func, and deinit. Each one is called in the main thread.
I have a NSWindow created in the init function.
What I need is to run the cocoa main loop ( [NSApp run] ) the handle messages of this window. I cannot run it in one of those 3 functions ( init, periodic func, and deinit), because [NSApp run] is blocking. And I must not block
the C main loop.
So I do not know where I can run it, because it seems it's not possible to run it in an other thread than the main thread (according to the documentation).

Ah ... if you can't start the C loop yourself, so you are forced to run the NSApp loop in another thread, then you need ot make sure that the thread you run the NSApp loop in is the 'main' thread as far as GNUstep is concerned.
This means you cannot use NSThread to create the thread.
You need to use plain C code and the native threading API to create a second thread from within the init function. In that second thread you would call GSRegisterCurrentThread() so that gnustep kows about it and would consider it the 'main' thread.

Then, once the gnustep thread is initialised as the 'main' thread, you also need to register the C loop's thread (perhaps the first time the periodic function is called) by calling GSRegisterCurrentThread() there too.

Once both threads are registered, it should be possible for the period function in the 'C' thread to call gnustep code in the 'gnustep' thread by using the preformInMainThread:... methods.





reply via email to

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