Threads in Delphi 4
Posted on 1998-11-08
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
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?