Hi Kapil,
I think you should have a look at select() function, it provides a
similar functionality. It allows you to monitor multiple file
descriptors ( i used them in sockets) and its really useful when the
descriptors are supposed to wait for read/write. You can constantly
check which FDs are ready to read/write. This will definitely solve your
high cpu consumption problem.
Regards,
Shashank
Kapil Agrawal wrote:
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
--
Shashank Sahni
Be a Linuxer - http://linuxers.org
Join us on Facebook http://www.facebook.com/pages/Linuxers/192912576144
_______________________________________
Pune GNU/Linux Users Group Mailing List