FLTK logo

Re: Updating main window while another thread is sleeping

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: Updating main window while another thread is sleeping Ian MacArthur Jun 20, 2012  
 
On 20 Jun 2012, at 20:32, William wrote:

>> Hello, I'm fairly new to FLTK but I am having some trouble getting a Fl_Valuator to update from a callback.  I currently have the following callback on a button:
>> 
>> {
>>  boost::thread t(boost::bind(&MotorControl::Sweep, motor_control));
>> }
>> 
>> This should call the MotorControl::Sweep method in a separate thread.  Within this method I issue the value(int) method on a few Fl_Valuators to change their values. There is also a boost sleep command between these method calls.
>> 
>> My issue is if I do not move the mouse, the Fl_Valuators (which are horizontal sliders) do not update their positions.  When I do move the mouse, the sliders instantly jump to their correct values.
>> 
>> How can I get the "Fl_Value_Slider"s to update correctly without me moving the mouse?
>> 
>> Thank you!
> 
> 
> I found a solution that seems to work.  Calling Fl::check(); after setting with value(int) does the trick.

Actually, that is almost certainly the wrong way to go - see Matthias' post...

You need to read the manual (section 10 of the fltk-1.1 manual, or the "Advanced FLTK" section of the fltk-1.3 manual) and follow some of the recipes suggested there.

In summary though, calling Fl::check() from any thread other than the "main" thread is likely to croak in odd ways at some point (how and when is platform dependent!) so you need to us Fl::awake() instead, and you really do want to Fl::lock() and unlock() any widget accesses from the worker threads.
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'.