Solved

Threads in Delphi 4

Posted on 1998-11-08
2
222 Views
Last Modified: 2010-04-04
I want to create a thread that responds to specific (user generated) events.  I have a thread safe buffer, and I need the thread to process items placed in this buffer by another thread.  at the moment, this thread sits in a loop, constantly checking for anything in the buffer, but this seems to eat up processor time to the point where the main VCL thread is running so slowly that it is losing windows messages.  

is there a way to define an event/handler such that the thread is idle, until an item placed in the buffer generates an event that tells the thread to wake up and process the item.   if this is not possible, then is it possible to tell a thread to stay idle until it is told to 'wake up' and start processing?

my (very primitive) understanding of threads is that a thread must sit in a loop within its 'execute' method of the form:

WHILE NOT Terminated DO
BEGIN
  .
  .
  .
END;
 
but it seems that going round and round in this way eats up processor resources and time.  

am I confused?


also in relation to this, can anyone recommend a book on thread programming in delphi?

Thanks,

Ben
0
Comment
Question by:1750
2 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1346155
For that purpose I think using timer would be a better idea since it allows the system to function....

Correct me if I'm wrong..

Cheers,
Viktor
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1346156
When the thread that is processing the items runs out of work it should suspend itself. When something is added to the list the thread should be resumed if suspended.

See the resume and suspend methods of TThread.

(Yes, you are right - having the thread run around in a tight loop waiting for work is not doing your system performance any good at all...)

Cheers,

Raymond.

PS: I can't really reccoment a good book. Most of the books just tend to regurgigate the help files anyway...
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question