Solved

Threads in Delphi 4

Posted on 1998-11-08
2
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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