Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Threads in Delphi 4

Posted on 1998-11-08
2
Medium Priority
?
227 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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