The class Concurrency::unbounded_buffer
can store any number of messages. But how to know number of pending (not received) messages?
Asked
Active
Viewed 589 times
0

Ajay
- 18,086
- 12
- 59
- 105
1 Answers
2
There's no functionality built in to do this.
What you can do is atomically increment/decrement an integer alongside it, but know that this won't be a reliable count (only a ballpark) if it's being accessed concurrently.
long count;
Concurrency::unbounded_buffer<T> buffer;
if(Concurrency::send(buffer, T()))
{
long new_count = _InterlockedIncrement(&count);
}
And elsewhere:
T value = Concurrency::receive(buffer);
long new_count = _InterlockedDecrement(&count);
You'll find the _Interlocked functions in <intrin.h>
.

Cory Nelson
- 29,236
- 5
- 72
- 110
-
Yes, you are right - there is no existing accessibe function/member to gain this information. I found out `_M_message_buffer` if type `_Queue`. The `_Queue` class is having `_Count` method. But unfortunately, this variable (of type `_Queue`) is declared as private in `unbounded_buffer` class – Ajay Aug 08 '11 at 10:15