Link to home
Start Free TrialLog in
Avatar of 1750
1750

asked on

Threads in Delphi 4

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
Avatar of viktornet
viktornet
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial