- More information on libs used

- amended Makefile to make the stock glibmm thread test compile
- amended Makefile in assumption that compile will fail too when source files are given at wrong position
- add thread.cc from the glibmm example directory (good test to see all is fine)
- fixed test.cpp (but doesn't compile yet)
master
Steve Clement 2013-07-16 12:59:43 +02:00
parent 2563177bf0
commit 6b3899c141
4 changed files with 122 additions and 4 deletions

View File

@ -6,6 +6,9 @@ Currently used versions of dependencies:
-- Documentation: http://www.boost.org/doc/libs/ -- Documentation: http://www.boost.org/doc/libs/
- libglibmm 2.35.9 - libglibmm 2.35.9
-- Documentation: https://developer.gnome.org/glibmm/2.35/ -- Documentation: https://developer.gnome.org/glibmm/2.35/
- libglib 2.36.0
-- Documentation: https://developer.gnome.org/glib/2.36/
-- Deprecation notices: https://developer.gnome.org/glib/2.36/glib-Deprecated-Thread-APIs.html
- libncurses 5.9 - libncurses 5.9
-- Documentation: http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/ -- Documentation: http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/

View File

@ -1,4 +1,6 @@
frameserver: frameserver:
g++ -O2 -ggdb -lncurses `pkg-config --libs --cflags glibmm-2.4` `pkg-config --libs --cflags gthread-2.0` -lboost_system -o frameserver Buffer.cpp Buffers.cpp Server.cpp frameserver.cpp g++ -O2 -ggdb -lncurses Buffer.cpp Buffers.cpp Server.cpp frameserver.cpp `pkg-config --libs --cflags glibmm-2.4` `pkg-config --libs --cflags gthread-2.0` -lboost_system -o frameserver
test: test:
g++ -O2 -pipe -fomit-frame-pointer `pkg-config --libs --cflags glibmm-2.4` `pkg-config --libs --cflags gthread-2.0` -o test Buffer.cpp Buffers.cpp test.cpp g++ -O2 -pipe -fomit-frame-pointer Buffer.cpp Buffers.cpp test.cpp `pkg-config --libs --cflags glibmm-2.4` `pkg-config --libs --cflags gthread-2.0` -o test
thread_test:
g++ -O2 -pipe -fomit-frame-pointer thread.cc -o thread `pkg-config --cflags --libs glibmm-2.4`

View File

@ -31,8 +31,8 @@ int main(void)
buffers = new Buffers(NUMBUFS); buffers = new Buffers(NUMBUFS);
vector<Glib::Thread*> readers; vector<Glib::Threads::Thread::*> readers;
vector<Glib::Thread*> writers; vector<Glib::Threads::Thread::*> writers;
for(int i = 0; i < NUMTHREADS; i++) for(int i = 0; i < NUMTHREADS; i++)
{ {

113
frameserver/thread.cc Normal file
View File

@ -0,0 +1,113 @@
#include <iostream>
#include <queue>
#include <glibmm/threads.h>
#include <glibmm/random.h>
#include <glibmm/timer.h>
#include <glibmm/init.h>
namespace
{
class MessageQueue : public sigc::trackable
{
public:
MessageQueue();
~MessageQueue();
void producer();
void consumer();
private:
Glib::Threads::Mutex mutex_;
Glib::Threads::Cond cond_push_;
Glib::Threads::Cond cond_pop_;
std::queue<int> queue_;
};
MessageQueue::MessageQueue()
{}
MessageQueue::~MessageQueue()
{}
void MessageQueue::producer()
{
Glib::Rand rand (1234);
for(int i = 0; i < 200; ++i)
{
{
Glib::Threads::Mutex::Lock lock (mutex_);
while(queue_.size() >= 64)
cond_pop_.wait(mutex_);
queue_.push(i);
std::cout << '*';
std::cout.flush();
cond_push_.signal();
}
if(rand.get_bool())
continue;
Glib::usleep(rand.get_int_range(0, 100000));
}
}
void MessageQueue::consumer()
{
Glib::Rand rand (4567);
for(;;)
{
{
Glib::Threads::Mutex::Lock lock (mutex_);
while(queue_.empty())
cond_push_.wait(mutex_);
const int i = queue_.front();
queue_.pop();
std::cout << "\x08 \x08";
std::cout.flush();
cond_pop_.signal();
if(i >= 199)
break;
}
if(rand.get_bool())
continue;
Glib::usleep(rand.get_int_range(10000, 200000));
}
}
}
int main(int, char**)
{
Glib::init();
MessageQueue queue;
Glib::Threads::Thread *const producer = Glib::Threads::Thread::create(
sigc::mem_fun(queue, &MessageQueue::producer));
Glib::Threads::Thread *const consumer = Glib::Threads::Thread::create(
sigc::mem_fun(queue, &MessageQueue::consumer));
producer->join();
consumer->join();
std::cout << std::endl;
return 0;
}