Solved

Threads in Delphi 4

Posted on 1998-11-08
2
218 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Deploying Delphi Application on Web Server 3 79
Delphi XE10, MySQL Query 4 109
find a node in VST 2 47
Downloading email attachments 2 55
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now