From: Paolo Farinelli (paolo++at++sgi.com)
Date: 04/10/2003 11:30:35
Hi Steve,
when the draw process is forked off within pfConfig, its copy of the
shared_area pointer is initialized to whatever the app process value is
at the time. In your code, it is undefined.
Subsequent modifications of the shared_area pointer in the app process
will only modify the app value and not the draw's, as the pointer itself is
not in shared memory.
You must either allocate your shared data before pfConfig, or at least
allocate your shared_area pointer in shared arena.
I have modified your code so that the pointer is allocated in shared
memory before pfConfig, here it is:
Hope this helps,
Paolo
#include <stdlib.h>
#include <stdio.h>
#include <new>
#include <Performer/pf.h>
#include <Performer/pf/pfPipe.h>
#include <Performer/pf/pfPipeWindow.h>
#include <Performer/pf/pfScene.h>
#include <Performer/pf/pfLightSource.h>
#include <Performer/pf/pfChannel.h>
#include <Performer/pfdu.h>
void windowSetup(char *title);
void sceneSetup(void);
void channelSetup(void);
void DrawFunc(pfChannel *chan, void *data);
struct Shared {
int shared_int;
};
Shared **shared_area;
pfuEventStream events;
pfScene *scene;
int main(int argc, char *argv[])
{
pfInit();
pfMultiprocess( PFMP_FORK_CULL | PFMP_FORK_DRAW );
pfdInitConverter(".flt");
shared_area = (Shared **)pfCalloc(1, sizeof(Shared*),
pfGetSharedArena());
pfConfig();
*shared_area = (Shared *)pfCalloc(1, sizeof(Shared),
pfGetSharedArena());
(*shared_area)->shared_int = 1;
windowSetup(argv[0]);
sceneSetup();
channelSetup();
while ( 1 ) {
pfFrame();
fprintf(stderr, "Value in APP: %d\n", (*shared_area)->shared_int);
void *arena = pfGetArena(*shared_area);
if ( arena )
fprintf(stderr, "APP: shared area allocated from arena: %8p\n",
arena);
else
fprintf(stderr, "APP: shared area allocated from heap\n");
}
return 0;
}
void DrawFunc(pfChannel *chan, void *data)
{
fprintf(stderr, "Value in DRAW: %d\n", (*shared_area)->shared_int);
void *arena = pfGetArena(*shared_area);
if ( arena )
fprintf(stderr, "DRAW: shared area allocated from arena: %8p\n",
arena);
else
fprintf(stderr, "DRAW: shared area allocated from heap\n");
pfDraw();
}
void windowSetup(char *title)
{
pfPipe *pipe;
pfPipeWindow *win;
pipe = pfGetPipe(0);
win = new pfPipeWindow(pipe);
win->setName(title);
win->setSize(500, 500);
win->open();
}
void sceneSetup(void)
{
pfNode *model;
pfLightSource *light;
scene = new pfScene();
light = new pfLightSource();
scene->addChild(light);
pfFilePath("/usr/share/Performer/data");
model = pfdLoadFile("esprit.flt");
scene->addChild(model);
}
void channelSetup(void)
{
pfPipe *pipe;
pfChannel *chan;
pfCoord view;
pipe = pfGetPipe(0);
chan = new pfChannel(pipe);
chan->setScene(scene);
view.hpr.set(0.0f, 0.0f, 0.0f);
view.xyz.set(0.0f, -7.0f, 0.0f);
chan->setView(view.xyz, view.hpr);
chan->setTravFunc(PFTRAV_DRAW, DrawFunc);
}
Stephen Jeffrey wrote:
>Hi,
>
>I want to allocate data from the shared memory arena
>after calling pfConfig, and then access that data in
>the APP and DRAW processes. If the data in the arena
>is modified in the APP process, the change is not seen
>in the DRAW process. Also, when pfGetArena(data) is
>called from the DRAW process it returns NULL ie. it
>claims the data is not stored in the shared memory
>arena, yet when called from the APP process it correctly
>returns the address of the arena.
>
>It appears as though each process is getting its own
>copy of the data, and not sharing a single copy in
>the shared memory arena.
>
>A modified version of the performer demo code "basic.C"
>is shown below which exhibits the problem.
>
>Any ideas?
>
>cheers
>steve
>
>--
>
-- Paolo Farinelli paolo++at++sgi.com Member of Technical Staff, OpenGL Performer 1-650-933-1808 Silicon Graphics 1600 Amphitheatre Pkwy, Mountain View, CA 94043
This archive was generated by hypermail 2b29 : Thu Apr 10 2003 - 11:30:41 PDT