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 Matthias Melcher Jun 20, 2012  
 
On 20.06.2012, at 21: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.

There may be two issues here: 

1: since you are using threads, make sure that you don't create or delete windows from within a thread. All FLTK calls should be done in the main thread. That is a restriction of the underlying system calls. If you need to do FLTK stuff in threads, you need to use Fl::lock, ::unlock, and ::awake.

2: your mein thread must return from callbacks quickly. I don;t know much about boost, but if the call above blocks the FLTK main loop, you will not get any updates until you return from the callback (or call Fl::check() or Fl::wait(), but that has its own issues).

 - Matthias
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'.