[PLUG] high cpu utilization

Aditya Godbole aag.lists at gmail.com
Mon Nov 9 22:43:59 PST 2009

On Sun, Nov 8, 2009 at 10:18 PM, Kapil Agrawal <kapil.agl at gmail.com> 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.

Create a pipe. Write data into that pipe from thd_r. In thd_w, you can
do a blocking read on the pipe.


More information about the plug-mail mailing list