LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-07-2012, 06:31 AM   #1
eviatarkhen
LQ Newbie
 
Registered: Aug 2010
Posts: 18

Rep: Reputation: 0
Fast Producer, Slow Consumer


Hello all,

I have a Producer-Consumer situation, between threads. I have a working implementation of message queue that is internally implemented using Posix condition variables.
The problem is that the consumer is VERY slow compared to the producer, so while the consumer is processing the message (and hance don't "cond_waid") the producer keeps "cond_signal"ing.
My question is, does the signals queued/saved, so when the consumer finishes handling the message and return to the "wait" it would immediately return or do they get "lost"?
Do you propose any other scheme for this problem?

Producer {
while
//fast frequency
pthread_cond_signal()
}

Consumer {
while
pthread_cond_wait()
// very slow handling
}

Thank you and best regards,

Eviatar Khen
 
Old 03-08-2012, 11:57 AM   #2
mulyadi.santosa
Member
 
Registered: Sep 2011
Posts: 96

Rep: Reputation: 15
Hi Eviatar

I think in Linux, signal is queued, not lost.

But anyway, in your scenario, I think you don't need to wake up consumer too often. Why not implement something like ring buffer, where the producer keep adding new stuffs at the head, and consumer simply "eat" anything at the tail? And it will stop when tail==head. When it does happen, it means no more new stuffs added and consumer may sleep for certain interval.

Hope it helps...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Producer and Consumer problem teesha Linux - Kernel 1 02-26-2012 11:58 PM
Producer / Consumer Shared Data: semaphores, kernel threads? jhwilliams Linux - Kernel 1 12-04-2011 12:59 PM
script to sync producer consumer application. ufmale Programming 2 06-08-2010 09:55 AM
Producer & Consumer issue with php on mysql ufmale Programming 3 03-13-2008 02:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration