> I've a problem with an application I'm developing: it's an audio 
> player/recorder based on FmodEx library. For playing and 
> stopping audio 
> stream there isn't problems, but when I start recording, the 
> application 
> GUI freeze (damn!) while recording process goes on.
> 
> Any suggestion? Someone speaks me about thread... How can i 
> use this UFO?
> I'm working under windows Xp + Mingw 3.4.5 + CodeBlocks.
> 
> Any suggestion are appreciated!


OK, threading... Well, this is a complex subject, and there are many
(many) ways it can go wrong (and then be really hard to debug) so some
googling around for articles would probably help.

A quick answer will probably just be confusing and error prone - so
here's a quick and error prone answer anyway!

In general, you put all the gui stuff in the main thread (the one that
starts when main() is called) and that handles all the user interaction
and so forth.

When you need to start a thread to do some work in the background (e.g.
your recorder) you put it in a void function like this...

         void my_thread_function(void) {...}

And you start that from your main thread like this...

      _beginthread(my_thread_function, 0, NULL);

(under unix use pthread_create(...) instead)


That will start the second thread, but it can't access the display at
all.
For that, the simplest (but probably not best!) thing to do is have a
few global variables that the worker thread can update as it progresses,
and the main thread can poll them (via add_timeout() or otherwise) and
update the gui accordingly. Similarly, the main thread can use a global
to signal the worker thread to terminate...

If the worker thread really wants to access the gui itself, then it can
use Fl::lock Fl::unlock and Fl::awake to do this - but this introduces
some "synchronisation" between the two threads and may be undesirable in
(for example) an audio recording application... (the audio may stop when
the worker thread blocks waiting for access to the display, for
example.)

So - that's probably just enough info to really mess things up! But try
it and see - just be careful!

Cheers,
-- 
Ian








SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
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.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to