> > Generally said, what I am trying to do is to make separate thread for
> > displaying each window.  I thought about creating multithreaded
> > callback function for each window's redraw,or redesigning main loop's
> > work, or something like that.The aim is to make each window run
> > absolutely separately,so that if there is some ,for example, endless
> > loop in one of it, you 'd have a possibility to switch to another
> > window and continue work there.  I know that maybe it's kind of wrong
> > idea, but maybe you'll give me some clues for that, I really need that.
> > thanks in advance.
>
> We might need to get more insight into what you actually need to achieve, b=
> efore we can know how best to advise you, as there are multiple ways to get=
>  to the endpoint you describe here... Which is best for you, will depend on=
>  what you are hoping to achieve.
>
> So, anyway, some notes:
>
> - most host platforms only have a single graphics card, and access to the d=
> isplay through that cards is inherently serialised and single threaded
>
> - in particular, modifying the GUI context from multiple threads can be fra=
> ught with difficulties
>
> - threading is an option, but there are issues you need to take care of
>
> - many apps achieve the same effect by use of timer callbacks from a single=
>  thread
>
> - most host platforms very much prefer it if you access the graphics card f=
> rom the "main" thread of your app, i.e. the thread in which the main() func=
> tion was called; this thread is often "anointed" with special privileges th=
> at other child threads don't get by default... In particular creating / del=
> eting / hiding / showing windows from a child thread often goes quite badly=
> ! (Only do that from the main() thread as a rule.)
>
>
> What I usually do is put all the GUI work in the main() thread, and spawn o=
> ff child threads to do the actual work - these threads communicate back to =
> the GUI thread via the Fl::awake(...) mechanism. However, with judicious us=
> e of Fl::lock() and Fl::unlock() the child threads can safely update widget=
> s and windows that the main() thread has created. (Though the child threads=
>  must not call redraw() on the widgets - again, use of Fl::awake() is the w=
> ay.)
>
> That's the basics for using multiple threads with multiple windows, I think=
>  - did that make sense? Did it help?
>
> The alternative (using multiple timer callbacks in a single thread to "emul=
> ate" multiple threads, might actually be simpler in many cases..)
>
> What is it you need to achieve?
>
>
>
> Selex ES Ltd
> Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS=
> 14 3EL
> A company registered in England & Wales.  Company no. 02426132
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
>
 Thanks a lot, that information was really useful, but I need to clear few more 
things. First of all, let me describe my task to make it easier for you to 
understand what I need. I am trying to make a multithreaded text editor. 
Firstly I thought to make full process of redrawing of each window of the 
editor multi threaded, but as I understood from your arguments it's impossible 
because of graphics card restrictions.So my aim now is to make functionality of 
this windows multithreaded. All process of work with text editor is based on 
work with text buffer ( which in my design is unique for each window) and 
reacting on buttons callbacks like copy, open,etc. So, now my questions are:
1) Is it possible to make callback functions multithreaded? Maybe you can give 
some example?
2) The "lags"(long-term operations) in my program are unexpected by design so  
I don't know in which place to make FL::awake() to give control back to main 
thread. So I guess I need to combine multi threading with timer callbacks 
mechanism. Like "if window not responding for 2 sec, give control to another 
thread, while operation is still in progress".The main idea is that you work in 
one window while some operation continues in another one. What are your 
ideas/experience about these? Maybe some example? So far, if i do some 
long-time loop in one of the window's callback function another just stops as 
well.
3)How can I pass control back to child's thread from main thread? For example I 
made fl::awake() during some long-term operation,because user started input in 
other window but i need that operation to be done till end, so when user 
stopped input i want main thread to "return" to that position in child's thread 
where it was left.
P.S. I  I know that most of this things can be done ( and possibly easier) 
single threaded , but multiple threads is a must for this project. Thanks for 
your fast and informative response.
_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to