How to thread a call to ofRunApp ? [Solved]

Hi all,

Here is my problem :

void* startOF(void*)  
    ofAppGlutWindow window;  
    ofSetupOpenGL(&window, 800,600, OF_WINDOW);  
    // ofWindow is derived from ofBaseApp  
    // there comes the actual question :  
    ofRunApp(new ofWindow());  
    /**/std::cout<<"exit of_thread"<< std::endl;  
int main (int argc, char** argv)  
    // openFrameworks thread  
    pthread_t of_thread;  
    pthread_create(&of_thread, NULL, startOF, NULL);  
    // another thread  
    struct qt_argxs args = {argc, argv};  
    pthread_t qt_thread;  
    pthread_create(&qt_thread, NULL, startQt, &args);  
    // end of program  
    pthread_join(qt_thread, NULL);  
    pthread_join(of_thread, NULL);  
    return 0;  

As you can see, I have two threads in my app, and one is for openFrameworks. I would like to use pthread_join() to synchronise my app. When I close the openFramework window, the cout is not displayed. I might be wrong, but I think ofRunApp never returns, and therefor I never reach my “pthread_exit(NULL);”.
What would be the proper way to do what I want to do (this implies keeping openFramework in a separated thread ;D ) ?

yes, ofRunApp never ends actually, it’s a glut thing and there’s nothing to do about it so a join is not going to work. you use pthread conditions to signal one thread to another and know when the application has actually finished: when the exit method is called in testapp

I’m not shure I understand : what you suggest is a call to pthread_exit() in the exit method of my ofApp ?

no, you need something in your main thread to wait for the two threads you create, for the qt thread you can wait by joining it, for the OF thread since it’s never going to end you can wait using pthreads conditions:

in the main thread instead of joining the OF thread, lock and wait for a condition. then in your testApp exit() method signal that condition and the program will end.

you can also use poco conditions, the idea is the same but this are multiplatform:

Thx, I’ll try it then!
Also , since I’m new to this forum, can you tel me how to edit the topic name in order to mark it as “solved” ?

don’t you see a modify button in the upper right part of the post?

yup !

done, thanks again :wink: