Well, for starters, I find boost::python excellent. It may be that I'm doing something conceptually very wrong, but I find the python<->C++ interaction very easy to work with when using boost::python. It took me something like 50 lines of code to connect my C++ renderer, and PyCairo to create 2D vector graphics textures in python.
I have also worked with the boost thread libraries, and it took me practically no code to create a base class that allowes me to use threads Java style.
Example base class:
Code:
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/progress.hpp>
#include <boost/bind.hpp>
#include <boost/thread/condition.hpp>
#include <boost/utility.hpp>
#include <iostream>
/** */
class Thread : private boost::noncopyable {
private:
boost::condition thread_condition;
boost::mutex monitor;
/** */
virtual void __run() {
std::cout << "before run()" << std::endl;
run();
std::cout << "after run()" << std::endl;
delete this;
}
public:
/** */
virtual void run() = 0;
/** */
virtual void sleep(const int nseconds) {
boost::xtime t;
boost::xtime_get(&t, boost::TIME_UTC);
t.nsec += nseconds;
boost::thread::sleep(t);
}
/** */
virtual void start() {
boost::thread th(boost::bind(&Thread::__run, this));
}
protected:
/** */
virtual void wait() {
boost::mutex::scoped_lock thread_lock(monitor);
thread_condition.wait(thread_lock);
}
/** */
virtual void notify() {
thread_condition.notify_one();
}
Thread() {
std::cout << "Thread created." << std::endl;
}
virtual ~Thread() {
std::cout << "Thread destroyed." << std::endl;
}
};
And example of derived class:
Code:
/** */
class MyThread : public Thread {
private:
int id;
public:
MyThread(int _id) : id(_id) {}
/** */
void run() {
std::cout << "Thread[" << id << "] starting.." << std::endl;
sleep(2);
std::cout << "Thread[" << id << "] waiting.." << std::endl;
wait();
std::cout << "Thread[" << id << "] notified. done." << std::endl;
}
/** */
void doStuff() {
notify();
}
private:
~MyThread() {
std::cout << "Thread[" << id << "] destroyed." << std::endl;
}
};