Re: events and shared memory

[email protected] (Joshua N Pritikin) Wed, 10 Oct 2012 08:34:13 -0400
Newsgroups perl.loop
Message-ID <20121010123413.GC3937@ubuntu>
On Wed, Oct 10, 2012 at 01:40:22AM -0700, Max V. Bouglacoff wrote:
> I'm trying to use Event module along with IPC::Shareable. The problem i=
s
> that Event does not react on changes of scalar vars placed in shared me=
mory.
> The code looks like this:
>=20
> ...
>=20
> tie $VAR,=A0 'IPC::Shareable',=A0 'SCAL';
> ...
> Event->var(
> =A0=A0=A0 var =3D> \$VAR,
> =A0=A0=A0 poll =3D> 'w',
> =A0=A0=A0 cb =3D> sub {
> =A0=A0=A0=A0=A0=A0 # some code
>=20
> =A0=A0=A0 }
> =A0 );
> ...
> To clarify: when first process modifies $VAR the
> changes are visible in second process immediately, but
> there is no reaction on Event facility (in second process).
>=20
> Would you be so kind to help me with this?

Event's var watcher depends on perl triggering the watcher when=20
modifying the variable. This will not happen when the variable is=20
modified by another process.

Rather than using shared memory, I recommend you create a socket pair=20
(like a pipe) between the two processes. Then you can write a byte on=20
one side and use the Event io watcher to notice in the receiving=20
process. Will this work for your use case?

> =3D=3D=3D=3D=3D=3D=3D=3D=3D
> This is perl, v5.8.8 built for i486-linux-thread-multi
> Event-1.20
> IPC-Shareable-0.60
>=20
> Linux breslau 2.6.36 #2 SMP PREEMPT Thu Jan 13 10:56:43 EET 2011 i686 A=
MD Athlon(tm) 64 X2 Dual Core Processor 5200+ AuthenticAMD GNU/Linux
> Slackware 12.1.0

--=20
Joshua N. Pritikin
Department of Psychology
University of Virginia
Gilmer Hall 102; Charlottesville, VA 22903
http://people.virginia.edu/~jnp3bc