G
Guest
I have an application that has a main thread and a worker thread.
From time to time, the main thread, because of user input, needs to notify
the worker thread to execute an extra bit of code, in addition to it's normal
work load.
I created 5 AutoResetEvent objects and have the main thread call set when it
wants the worker thread to execute some additional code. In the worker
thread, I have 5 separate WaitOne(0,false) functions being called; one for
each AutoResetEvent object . It was my hope that the worker thread would do
a quick check (no wait time) to see if the event was set and then proceed
with it's other work.
Unfortunately, there appears to be some overhead with this WaitOne()
function, because my CPU usage is running at about 70% when I have these 5
WaitOne() functions in the worker thread. However, if I comment them out,
the CPU usage drops to about 15%.
Does anyone know why this is such a drain on the system? Am I misusing
these Events? Is there a better or more efficient way to signal between
threads?
Thanks for your help.
Phil
From time to time, the main thread, because of user input, needs to notify
the worker thread to execute an extra bit of code, in addition to it's normal
work load.
I created 5 AutoResetEvent objects and have the main thread call set when it
wants the worker thread to execute some additional code. In the worker
thread, I have 5 separate WaitOne(0,false) functions being called; one for
each AutoResetEvent object . It was my hope that the worker thread would do
a quick check (no wait time) to see if the event was set and then proceed
with it's other work.
Unfortunately, there appears to be some overhead with this WaitOne()
function, because my CPU usage is running at about 70% when I have these 5
WaitOne() functions in the worker thread. However, if I comment them out,
the CPU usage drops to about 15%.
Does anyone know why this is such a drain on the system? Am I misusing
these Events? Is there a better or more efficient way to signal between
threads?
Thanks for your help.
Phil