FLTK logo

Re: [fltk.general] Use worker thread to call Fl_Window and Fl_run

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Use worker thread to call Fl_Window and Fl_run "anmol.... Oct 01, 2020  
  Wouldnt Fl::run() block the main loop though ? Thats what I am trying to avoid as its a loop that processes lots of data.

On Thursday, October 1, 2020 at 7:09:47 PM UTC+5:30 lifeatt...@gmail.com wrote:
I've had some success with a message-based system.

In the forked process I invoke Fl::handle_() with a custom message code. In the main code I establish a handler using Fl::add_handler(). Fl::run() operates as normal.  Something like:

int progress_update(int event)
{
    progress->value((float)event_data); // using FL's event_data global for data transfer
    char percent[10] = {""};
    sprintf_s(percent, "%d%%", (int)event_data);
    progress->copy_label(percent);
}

int main()
{
    Fl::add_handler(progress_update);
// create window as shown earlier
    Fl:run()
}

and in the worker thread:
    event_data = t / 500.0;
    Fl::handle_(PROGRESS_UPDATE,0);


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/c9fb305b-3e7e-4000-bb4f-df747df70080n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.