Hi all,
I gave up mutex, I tried to work with the osg aspects and changelists
My problem is, if I use different Aspects I need to sync them.. but then the
main thread will wait for all the other threads before rendering..
I would like to have the main thread sync the data only when the second
thread is allready waiting! is there a method to get the number of thread
which are allready waiting at a barier?
I used code found in the archives and the multithreading tutorial, this is
what I have :
//code from
http://www.mail-archive.com/[email protected]/msg03575.html
class OSGThread : public osg::ExternalThread
{
public:
typedef boost::shared_ptr<ExternalThread> Ptr;
static Ptr create(const char* szName, int uiId) {
return Ptr(osg::ExternalThread::create(szName, uiId),
boost::mem_fn(&osg::MemoryObject::subRef));
}
};
OSGThread::Ptr osgThread;
Thread *mainThread;
Barrier *syncBarrier;
class RotatingCube {
public:
RotatingCube(NodePtr c) {
trans = Transform::create();
tnode = Node::create();
beginEditCP(tnode);
tnode->setCore(trans);
tnode->addChild(c);
endEditCP(tnode);
}
TransformPtr trans;
NodePtr tnode;
bool go;
void startThread() {
boost::thread(boost::bind(&RotatingCube::run,this));
}
void run() {
osgThread = OSGThread::create("test1", 0);
osgThread->initialize(1);
syncBarrier->enter(2);
mainThread->getChangeList()->applyAndClear();
syncBarrier->enter(2);
while (go) {
rotate();
syncBarrier->enter(2);
syncBarrier->enter(2);
}
}
void rotate() {
osgsleep(10);
Matrix m,n;
n = trans->getMatrix();
m.setRotate(Quaternion(Vec3f(1,1,1), 0.001));
m.mult(n);
beginEditCP(trans);
trans->setMatrix(m);
endEditCP(trans);
}
};
RotatingCube* rc;
int main(int argc, char **argv)
{
ChangeList::setReadWriteDefault();
osgInit(argc,argv);
int winid = setupGLUT(&argc, argv);
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
syncBarrier = Barrier::get("anim");
mainThread = dynamic_cast<Thread *>(ThreadManager::getAppThread());
rc = new RotatingCube(makeBox(1,1,1,1,1,1));
rc->startThread();
NodePtr scene = rc->tnode;
mgr = new SimpleSceneManager;
mgr->setWindow(gwin);
mgr->setRoot(scene);
mgr->showAll();
glutMainLoop();
return 0;
}
void display()
{
syncBarrier->enter(2);
osgThread->getChangeList()->applyAndClear();
syncBarrier->enter(2);
mgr->redraw();
}
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users