[vorbis-dev] Multithreading

Oliver Jones odjones at odjones.com
Sat Jan 11 12:10:34 PST 2003



Hello.

Yes, you can. For my 2nd year Software Engineering workshop back when I was
at University, I had to do something similar. The GUI was managed with Motif
1.2 and the application was sound sampling/playback. The sound driver (some
hideous contraption designed by Microsoft, no less!) busy-waited on
recording and playback, so I had to run that as a separate thread to keep
control of my GUI (hitting the "stop" button is a little difficult,
otherwise!) :)

Bear in mind a few caveats when programming multithreaded applications:

a) you need to think 5th-dimensionsionally (parrallelism) when it comes to
debugging (your data is SHARED between threads, NOT replicated as with
processes spawned via fork() etc!)

b) with point a in mind, use POSIX mutexes to arbitrate access to your data
(allowing two or more threads to stampede over your data is a recipe for
disaster, and then some). Something like pthread_mutex_create() will do the
trick. A good book for multithreaded programming is "Multithreaded
programming with Pthreads" by Lewis & Berg. This will explain both thread
creation with the POSIX thread library - and more importantly, controlling
your threads with mutexes.

c) make sure all your libraries are MT-safe (multithreaded-safe). Motif 1.2
was *not* - although I have heard since that version 2.2 (check out
OpenMotif) is now MT-safe. For non MT-safe libraries, you'll need to
sandwich library calls in a mutexlock-call-mutexunlock structure.

d) plan it carefully! Software engineering can quite easily turn into a
dog's breakfast if you let it, but multithreaded applications are a
particularly nasty breed of monster if you let them get out of hand. Don't
use so many mutexes that you lose track of them all - but bear in mind that
for any useful MT application, they are necessary.

Hope this is of some help to you.

Kindest regards,

Oliver.

-----Original Message-----
From: owner-vorbis-dev at xiph.org [mailto:owner-vorbis-dev at xiph.org]On
Behalf Of Spork Michael
Sent: 11 January 2003 14:18
To: vorbis-dev at xiph.org
Subject: [vorbis-dev] Multithreading

<p>Hi.
I need to execute a function from within a GUI.
This seems to be no problem but this function takes about 4 minutes to
finish, which means the application doesn't react at all, while the
function is running.
Can I execute a function as a separate Thread, while keeping
control(e.g. a reference) of it at the same time?
If not, how do this with a class containing this function?

thanks,
stephan

<p><p><p>_________________________________________________________________
MSN Groups & Chat - Freunde finden - leicht gemacht
http://groups.msn.com/people/

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to
'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list