Hi Carsten!
I've tried to use the provided openSG multithreads to solve my problems,
but I've run into two different obstacles.
First problem is in a dummy-program I made just to test the
multithreading. Where I wish to add another box to the scene after 5
seconds of execution. I've modified the 01hello tutorial file.
The main-thread is stuck in the glut-main loop, and it's constantly
running the display function, witch looks like:
void display(void) {
if (needSync == true) {
needSync=false;
syncBarrier->enter(2);
thread->getChangeList()->applyAndClear();
syncBarrier->enter(2);
}
mgr->redraw();
}
The other thread is running another function that looks like:
void foo(void *ptr){
sleep(5);
// add a box to the scene
needSync=true;
NodePtr bar = makeBox(2,3,4,1,1,1);
// scene is the scene-root, and is a torus.
beginEditCP(scene);
scene-addChild(bar);
endEditCP(scene);
syncBarrier->enter(2);
syncBarrier->enter(2);
// do nothing
while(true) {
sleep(1);
std::cout << "thread lives\n";
}
}
After the synchronization the scene gets blank and the command prompt
gives the warning:
WARNING: recurse: core is Null, don't know what to do!
How to solve this?
And the other problem :)
In another program I'm building, the Barrier seams to fail every now and
then, giving the error code:
*** glibc detected *** double free or corruption (out): 0x082767f0 ***
In the main file i start two separate threads, one witch creates and
initialize an clusterclient object And then proceeds to the glut main loop.
In the clusterclient file, there are functions that I use to manipulate
the scene. But I wish to be able to do all manipulation externally, and
then just call for synchronization to update all possible changes.
///// taken from main file
// this is run by a separate thread in the main file
void createOpenSGHandle(void *ptr){
std::cout << "Client handle starts\n";
// init openSG thread handling - to allow external interaction
osg::ExternalThread::get(0)->initialize(0);
while(true){
sleep(7);
std::cout << "client handle lives\n";
// manipulate scene - add objects and so on
client->callSync();
}
}
///// end of main file
//// taken from the clusterclient file
void OpenSGClient::callSync(){
std::cout << "callSync called\n";
needSync = true;
syncBarrier->enter(2);
syncBarrier->enter(2);
}
// one thread is running this loop
void display(){
if(needSync==true) {
needSync = false;
syncBarrier->enter(2);
clientHandle->getChangeList()->applyAndClear();
syncBarrier->enter(2);
}
mgr->redraw();
OSG::Thread::getCurrentChangeList()->clearAll();
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
//////// end of cluster client file
The program crashes most of the time giving the error as I mentioned
above. I've noticed that the line: syncBarrier->enter(2); in the display
function is what kills the program. syncBarrier is a static variable in
the clusterclient class and is declared when constructing a
clusterclient object. osginit and changelist:: setreadwritedefault is
declared in the main file, before creating the cluster client object.
How to solve this?
Many thanks for any input!
// Martin
>Hello Martin,
>>Martin Karlsson wrote:
>>Thanks! that solved one part of the problem :) I don't get any
>>segmentation faults anymore but I've run into another problem.
>> The external thread does not seam to be able to add objects to the
>> ClusterClient thread. I think this is because the ClusterClient have
one
>> instance of the osg init, and when I'm creating object using
>> clinet->addTorus() from the main-thread, they belong to the
main-thread.
>> Does this make any sense? :) I think that the new objects that i
wish to
>> add doesn't get added to the clients sceneograph. What to do? :)
>what aspects are your threads using and do you sync them (see
>https://opensg.vrsource.org/trac/wiki/Tutorial/OpenSG1/Multithreading
>for the relevant tutorial chapter that describes these things) ?
>Cheers,
>Carsten
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users