http://www.perlmonks.org?node_id=1053722

Codeman_Rhodes has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have a problem with some perl code I need to write for sending DMX data to an Open-Lightning-Architecture-Daemon (that's for lightning of stages and so on).

I have written a class which connects to the "olad" and starts a background thread which sends regulary DMX-data to the daemon. For changing the DMX-data I have accessors defined.

My problem is, that the thread does no see changes inside the DMX-data. I started the thread with a reference to $self as an argument and inside the thread I use the argument as $super. I can dump all data from $super but if something outside the thread changes the data, this is not seen inside the thread. It seems that the thread has got a copy of %self instead of a reference.

I also tried to use shared(%self) - but I don't know how to access this data.

Here is my (test) code (TTTT.pm) withoud shared()-tests:

#/usr/bin/perl package TTTT; use threads; use threads::shared; use Data::Dumper; sub new { my $class=shift; my $self={ universe=>shift }; $self->{'_dmx_channels'}=chr(0)x512; $self->{'_thread'}=threads->create(\&worker_thread,\$self); return(bless(\%self, $class)); } sub set { my($self,$channel,$value)=@_; vec($self->{'_dmx_channels'},$channel,8)=$value; } sub worker_thread { my ($super)=@_; while(1) { $i++; print "Thread: $i:".$$super->{'universe'}."\n"; for($n=0;$n<30;$n++) { print int(vec($$super->{'_dmx_channels'},$n,8) +).","; } print "\n"; sleep(2); } } 1;

I tried to use the "set"-function and I tried to change the universe - the main program shows the changes, the thread does not.

What I am doing wrong?

Thanks, Holger