Wednesday, May 29, 2013

Multithreading in FLTK

The very smart way: http://www.fltk.org/doc-1.3/advanced.html
int main() {
      Fl::lock();
      /* run thread */
      while (Fl::wait() > 0) {
        if (Fl::thread_message()) {
          /* process your data */
        }
      }
    }

//////////////
void *msg;       // "msg" is a pointer to your message
Fl::awake(msg);  // send "msg" to main thread

//////////////

void do_something(void *userdata) {
      // running with the main thread
    }

    // running in another thread
    void *data;       // "data" is a pointer to your user data
    Fl::awake(do_something, data);  // call something in main thread

No comments: