message passing question

G

Gvs

Hi,

I'm currently trying to pass messages into a queue. This all works fine,
however, i'm trying to my program to stop sending messages to the queue when
it reaches an upper threshold. At present this threshold is the number of
chairs in a waiting room. This is an int represented by nChairs.

So i want to compare this to the number of messages in my queue. I'm using
the following lines of code to do this, however the queue is always saying
it has 0 messages, i check with ipcs and it has multiple (+30) some times.
What am i doing wrong ?

---------------------

while (ds.msg_qnum < nChairs)
{
printf("number of chairs : %d\n", nChairs);
printf("number of messages : %d\n", ds.msg_qnum);
}

----------------------

I have more code that adds the messages inside this while loop .. but i
ommitted it for simplicity.

Matt
 
K

Keith Thompson

Gvs said:
I'm currently trying to pass messages into a queue. This all works fine,
however, i'm trying to my program to stop sending messages to the queue when
it reaches an upper threshold. At present this threshold is the number of
chairs in a waiting room. This is an int represented by nChairs.

So i want to compare this to the number of messages in my queue. I'm using
the following lines of code to do this, however the queue is always saying
it has 0 messages, i check with ipcs and it has multiple (+30) some times.
What am i doing wrong ?

---------------------

while (ds.msg_qnum < nChairs)
{
printf("number of chairs : %d\n", nChairs);
printf("number of messages : %d\n", ds.msg_qnum);
}

----------------------

We have no way of knowing from what you've posted. Apparently ds is a
structure with a member called msg_qnum, but you haven't told us
anything more about it, and we don't know what "ipcs" is.

When you say that "the queue is always saying it has 0 messages", do
you mean that ds.msg_qnum==0?

In the code fragment you provided, there's nothing that could change
the value of ds.msg_qnum, so if it executes at all it's an infinite
loop.

If this is part of something system-specific, you'll need to ask in a
system-specific newsgroup. If it's part of your own software, you'll
need to provide more details.
 
P

Peter Shaggy Haywood

Groovy hepcat Gvs was jivin' on Thu, 19 May 2005 13:13:48 +0800 in
comp.lang.c.
message passing question's a cool scene! Dig it!
I'm currently trying to pass messages into a queue. This all works fine,
however, i'm trying to my program to stop sending messages to the queue when
it reaches an upper threshold. At present this threshold is the number of
chairs in a waiting room. This is an int represented by nChairs.

So i want to compare this to the number of messages in my queue. I'm using
the following lines of code to do this, however the queue is always saying
it has 0 messages, i check with ipcs and it has multiple (+30) some times.
What am i doing wrong ?

---------------------

while (ds.msg_qnum < nChairs)
{
printf("number of chairs : %d\n", nChairs);
printf("number of messages : %d\n", ds.msg_qnum);
}

Umph! A guy goes to his local mechanic and says, "My car has
something wrong with its gearbox. I can't change gear. I've brought
along the locking bolts from a couple of the cogs inside the gearbox
to show you. What could be the trouble?"
What do you think the mechanic said to the guy? Now you know what we
want to say to you.
Please post the smallest *complete* program that demonstrates the
problem. By "complete" I mean something you expect to compile and run.
If your program is long, cut out everything extraneous, leaving just
enough to show the problem - but *complete*. And make sure what you
post actually does show the problem. You'll also need to tell us
exactly how the code is supposed to work, as well as a concise but
reasonably detailed description of the behaviour you observe and how
this differs from the behaviour you expect.
We can't tell anything from what you have posted. We're not mind
readers. You have to give us something to go on.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top