Re: how to implement the function getmsgwait() from memory queue?

From: Lev Walkin (
Date: 09/07/04

Date: Tue, 07 Sep 2004 06:13:46 -0700

Jaguk Ku wrote:
> Hi there,
> I made a shared memory queue, and i implemented the function getmsg() from
> the queue.
> the function getmsg() works like this
> getmsg()
> {
> lock the queue
> check the stored count
> read the stored item
> unlock the queue
> }
> if there is no stored item, i have to call getmsg() function continuously.
> i don't like this.
> i would like to make function, getmsgwait(int waittime) which can wait until
> some item is stored in the queue or waittime expires.
> Would anyone like to tell me how to implement it

use condition variables and broadcast insertion of a new item into the queue.
in posix world, it's pthread_cond_init(3)/pthread_cond_broadcast(3).
Use pthread_cond_timedwait(3) to implement waittime.

Lev Walkin