Hello Victor, On Fri, Sep 11, 2009 at 9:52 AM, Victor Haefner <[email protected]> wrote: > I am trying to use boost threads, but it seems that mutex won't work.. most > of the time it crashes.. > even without starting the thread > > well, I am a total nobb with threads :/ ..I managed to make the threads > work, but this was the easy part.. > to copy information between threads is the big problem (thread safe) > > I tried mutex, but just writing to an object with mutex locked can lead to a > crash (doesn't allways, don't know why, it seems it crashes if I copy > NodePtr and such..) > > I don't know if its right what I did :
hm, well, a full description of all the pitfalls when programming with threads is probably a bit beyond the scope of the list ;) However, to figure out the concrete problem you are having, it would be very helpful to have a description of what you are trying to do ;) OpenSG is designed to make multithreading easier (at least some parts of it), specifically a lot of the internals are arranged in a way that allows multiple threads to access the scenegraph without fine grained synchronization. To that end every thread OpenSG knows about (threads created with external thread libs can be used, but need to be registered) is associated with an "aspect" (essentially a copy of a FieldContainer). Changes made in each thread are recorded in changelists and when the application decides it is a good idea to synchonize different threads (e.g. end of a frame) it can use these lists to transport changes from one aspect to another. More information on these things can be found in the tutorial (<http://opensg.vrsource.org/trac/wiki/Tutorial/OpenSG1/Multithreading>); this page has not been adapted for OpenSG 2.0 yet, but you seem to be using 1.x anyways :) > class threadContainer {// I use this to pass informations from a > Intersectaction > public: > threadContainer(){ > hitObj = NullFC; > hit = false; > hitPnt = Pnt3f(0,0,0); > } > ~threadContainer(){ > ; > } > > void set(bool h, NodePtr n, Pnt3f hpnt) { > hit = h; > hitObj = n; > hitPnt = hpnt; > } > > boost::recursive_mutex mutex; > NodePtr hitObj; > bool hit; > Pnt3f hitPnt; > }; > > and I try to write with : > > > if (updateIntersect and iAct_tc != 0 and iAct != 0) {//iAct_tc > is my container of type threadContainer > > iAct->setLine(getLine()); > if (IntersectNode != NullFC) { > iAct->apply(IntersectNode); > if (cur != 0) cur->checkPointer(iAct); > } > > bool hit = iAct->didHit(); > NodePtr node = NullFC; > Pnt3f hitPnt; > if (hit) { > hitPnt = iAct->getHitPoint(); > node = iAct->getHitObject(); > } > > boost::recursive_mutex::scoped_lock > lock(iAct_tc->mutex);//lock iAct_tc mutex to write > iAct_tc->set(hit, node, hitPnt); > } > > so should i use osg locks? (if yes then how?^^) > or something completly different? > or is it bullshit what I am doing? :D I honestly can not say, it depends on which threads the above code snippets run in and what else is going on in your application. If you describe what should happen, please also mention if you want to run it in a thread and what you roughly expect to happen in other threads (e.g. you might be doing intersection tests in one thread, while another one renders your scene and a third one loads models). Cheers, Carsten ------------------------------------------------------------------------------ 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
