[PLUG] high cpu utilization

Kapil Agrawal kapil.agl at gmail.com
Sun Nov 8 08:48:54 PST 2009


Hi,

I am stuck on the following problem, please help me in finding a solution.

In my C program, I have two threads,
thd_r reading video realtime from an hardware  and  thd_w writing to a file.
thd_r is very slow (as it real time video capture) as compared to thd_w. To
push data from one thread to another  push a buffer in a g_queue which get
pulled in the thd_w and used. But since thd_r is much slower then thd_w,  I
have to wait in thd_w again and again in a while loop polling for the data
to be pushed queue from thd_r. Because of this polling using while, huge CPU
is getting consumed.
   This I try fixing by putting a usleep in the while loop , hence there is
a small decrease in cpu utilization.

But its a not so good hack, nor a right fix. Right thing would be that I put
my thd_w in sleep till there is no data in the queue and once thd_r pushes
some data in queue the thd_w should wake up to consume. But I am not sure
how can I achieve this ?
Can someone please point me to right solution.

Note: Both these threads are completely independent and I can't share there
memory space etc. I dont have control over the hardware so that I can send
some interupts etc.

Looking forwrad to a solution.

Thanks
Regards
Kapil
-- 
http://www.linkedin.com/in/kapilagrawal


More information about the plug-mail mailing list