A glibmm thread example.
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#include <glibmmconfig.h>
#endif
#include <glibmm/init.h>
#include <glibmm/random.h>
#include <glibmm/timer.h>
namespace
{
class MessageQueue
{
public:
MessageQueue();
~MessageQueue();
void producer();
void consumer();
private:
};
MessageQueue::MessageQueue()
{
}
MessageQueue::~MessageQueue()
{
}
void
MessageQueue::producer()
{
for (auto i = 0; i < 200; ++i)
{
{
cond_pop_.wait(
lock, [
this]() ->
bool {
return queue_.size() < 64; });
queue_.push(i);
cond_push_.notify_one();
}
continue;
}
}
void
MessageQueue::consumer()
{
for (;;)
{
{
cond_push_.wait(
lock, [
this]() ->
bool {
return !queue_.empty(); });
const int i = queue_.front();
queue_.pop();
cond_pop_.notify_one();
if (i >= 199)
break;
}
continue;
}
}
}
int
main(int, char**)
{
MessageQueue queue;
const auto producer =
const auto consumer =
producer->join();
consumer->join();
return 0;
}
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
gint32 get_int_range(gint32 begin, gint32 end)
void usleep(unsigned long microseconds)
void init()
Initialize glibmm.