Closing TApplication from a separate thread

Hello,

I would like to create a program with several threads, one of which being the root event loop. At the end of the job, I would like that thread to close cleanly. However I don’t understand how to do that.

Here is a simple example:

[code]#include “TApplication.h”
#include <pthread.h>
#include <unistd.h>
#include
using namespace std;

void *rootGuiLoop(void app)
{
cout << “Entering Root message loop.” << endl;
reinterpret_cast<TApplication
>(app)->Run(kTRUE);
cout << “Leaving Root message loop.” << endl;
return NULL;
}

int main(int argc, char argv[])
{
pthread_t thread;
TApplication
app = new TApplication(“app”, NULL, NULL);
pthread_create( &thread, NULL, rootGuiLoop, app);

usleep(1000000);
cout << “Will now attempt to close application” << endl;

app->Terminate();

pthread_join( thread, NULL);

return EXIT_SUCCESS;
}
[/code]

In this case even though app->Terminate() is called, the event loop is never closed… Is there a correct way to do this?

Thanks,

Pierre-François

It would be much simpler if you leave the event loop for the main thread
and start the activate another thread using ROOT TThread class. Do you see any trouble this way?