[PLUG] high cpu utilization
Abhijit Bhopatkar
bain at devslashzero.com
Fri Nov 13 11:57:58 IST 2009
On Monday 09 Nov 2009 9:12:00 am Vivek Khurana wrote:
> On Sun, Nov 8, 2009 at 10:18 PM, Kapil Agrawal <kapil.agl at gmail.com> wrote:
> > But its a not so good hack, nor a right fix. Right thing would be that I
> Look at message passing.., I would run these two as separate
> processes and not separate threads. One process reads from video
> hardware and pushes data in a queue, another process consumes from the
> queue.
You certainly don't want to do that, passing whole data around processes is
way more expensive.
Anyway the right solution (as suggested in other response), is to use a
semaphore or if you are using pthreads library, a conditional variable.
Wait on the variable in write thread and wake the variable up from read thread
when the data is ready to be written.
WARNING: Don't forget to use proper locking that has to be passed around to
conditional variables.
Google will find you lot of docs on using conditional variables and common
mistakes made while using them. It can seem unusually complicated if you
haven't used them before, but will be very obvious once you start
understanding the internals.
BAIN
More information about the Plug-mail
mailing list