Re: Static variables

New Message Reply Date view Thread view Subject view Author view

Nicolas Gauvin (nicolas++at++cae.ca)
Wed, 20 Dec 1995 13:15:55 -0500


On Dec 20, 6:00pm, Andreas Brendstuen wrote:
> Subject: Static variables
>
> I am trying to use the functions in the env.* files that lies in the
> common directory (for perfly etc..)
>
> fog and fogColor are variables that are defined as static global in
> the env.c file. The initEnvironment function initiate these variable
> and if fog is not off, the updateTimeOfDay function updates them. My
> problem occurs when I'm testing my application on an Onyx with 4
> cpus. I call the initEnvironment when initializing and then
> updateTimeOfDay when I change the time of day. updateTimeOfDay uses
> the static variables, but when I check them, fog is NULL and fogColor
> is 0.0, 0.0, 0.0 (they are set to 1.0, 1.0, 1.0 in initEnvironment).
> Testing on an Indigo with one cpu, I don't have this problem.
>
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
> _/ Andreas Brendstuen _/ abrend++at++idt.unit.no _/
> _/ _/ http://www.idt.unit.no:80/~abrend _/
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
>-- End of excerpt from Andreas Brendstuen

You need to put those kind of informations into share memory when using
multiprocessing because Performer uses forked processes. If you don't, all
changes to static of global data that are made after pfConfig by the APP
process won't be seen from CULL or DRAW processes. One way to deal with this is
to use a shared arena. For example:

/* allocate shared before fork()'ing parallel processes */
Shared = (SharedData*)pfMalloc(sizeof(SharedData), pfGetSharedArena());

...

pfConfig();

Shared is a pointer to a user defined SharedData structure. Since the pointer
is initialised before pfConfig all processes get the same pointer pointing
in a shared memory section.

BTW perfly already has a share memory section called ViewState, simply add fog
and fogColor to it and so you can use ViewState->fog and ViewState->fogcolor;

-- 
     ___/     |       ___/ Nicolas Gauvin	   e-mail: nicolas++at++cae.ca
    /       / |      /     Software Developper	   voice: (514) 341-2000 x2275
   /       /  |     __/    CAE Electronics Ltd.    fax:   (514) 340-5496
  /       ___ |    /	   8585 Cote De Liesse, P.O. Box 1800
_____/  _/   _| _____/     Saint-Laurent, Quebec, Canada, H4L-4X4

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:10 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.