how to implement threads?

Leonardo B. Lopes leo at iems.nwu.edu
Fri Nov 17 16:22:01 GMT 2000


This summer for the first time I did some work with threads. I had an UI
with some serious calculations in the background, and I needed to give the
user the ability to interrupt the thread. This is what I learned:

	1) To learn about threads, try python. Write some simple programs
with competing threads (i.e., one thread increments a variable, another
decrements), pay close attention to the output, and you will learn a lot. 

	2) Learn how to use the access control classes, like mutexes,
semaphores, etc... and USE them. ESPECIALLY if you have two processors.

	3) Bill is right. Most GUIs are NOT thread safe. In particular,
GTK is not, and Win32 is not. I don't know about qt, but I suspect it
isn't either. In order to communicate with your thread, you will need some
type of message passing mechanism.

	4) Once you are confident about the nuances of threads, then you
can move to C/C++. Threaded programs are harder to debug, and more
verbose. I would be very surprised if qt doesn't have some thread classes.
But just because they are in qt, don't assume they are portable. Make sure
to check the docs. Bill is right that these things are very OS specific.

I don't know if that helps. Good luck!

Leo.

On Fri, 17 Nov 2000, Bryan, Bill wrote:

> I have 0 experience with coding threads, but this is what I do know.
> Threading is an O/S feature.  If KDE has threading in the API, then
> investigate it.  You should also look at the threading mechanisms that
> your O/S supports ( posix threads, p-threads, kernal threads.... ).  If 
> you have to use the O/S api's for threading, don't do seperate threads 
> for serperate pieces of the GUI interface ( I cannot say this is wrong from 
> experience, but it feels that way ).  I would look at threading off the 
> tasks that executed by the widgets in the GUI ( for example, when the user
> presses an ok button and I have to do several task, I would have them run
> serially or I could tread them to ensure that they execute simultanously -
> if the tasks are no dependent on each other ).
> 
> -----Original Message-----
> From: Oliver Sbanski [mailto:sbanski at mail.uni-wuerzburg.de]
> Sent: Friday, November 17, 2000 8:54 AM
> To: kdevelop at kdevelop.org
> Subject: how to implement threads?
> 
> 
> Hi,
> 
> I'm using kdevelop for my programming for a while, but I'm not too 
> experienced in programming, in particular I have never programmed threads.
> 
> I have a dual pentium and I want to make my program split into two processes
> 
> sharing the memory for speeding up the calculation...( 
> Is there a specially easy way to accomplish this under KDE, or in general, 
> does anyone know an easy introduction to thread programming?
> 
> Thanks,
> 
> Oli
> 
> -
> to unsubscribe from this list send an email to kdevelop-request at kdevelop.org
> with the following body:
> unsubscribe »your-email-address«
> 
> -
> to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
> unsubscribe »your-email-address«
> 

========================================================================
Leonardo B. Lopes                                       leo at iems.nwu.edu 
Ph.D. Student                                              (847)491-8470
IEMS - Northwestern University              http://www.iems.nwu.edu/~leo


-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«



More information about the KDevelop mailing list