How do you share an object(Telnet Session) between threads?

Update: I have a working version of this app using one Telnet Session thread along with the Wx GUI code. I will post this version to the Cool Uses for Perl section.

I need the Telnet session below available to 3 threads(connect, disconnect, & scan). $telnetsession is of type Net::Telnet per print(ref($telnetsession)).

This is part of a larger wxPerl script. All of the display and interlocking between the GUI and threads seems to working corectly.

Crossposted to wxperl-users.

Thanks, James

# Define the Thread shared data area - All threads access this scaler +data fine my %common : shared; $common{ip} = "127.0.0.1"; # Localhost $common{port} = "7356"; # Local Port as defined in gqrx $common{telnetsession} = 0; # Object Pointer ??? Problem ?? +? $common{tnerror} = 0; # Status $common{connect} = 0; # Command $common{connected} = 0; # Status $common{disconnect} = 0; # Command $common{scanstart} = 0; # Command $common{scanstarted} = 0; # Status $common{beginf} = 0; # Scan - Beginning Frequency $common{endf} = 0; # Scan - Ending Frequency $common{step} = 0; # Scan - Frequency Step $common{squelch} = 0; # Scan - Minimum RSSI(Recieved Signal + Strength Indicator) $common{rssi} = 0; # Scan - Latest RSSI $common{pause} = 0; # Scan - Time between scans - msec $common{listen} = 0; # Scan - Time to Listen to a strong si +gnal - msec $common{mode} = 0; # Scan - Demodulator Type $common{stopthreads} = 0; # Command # Connect the Telnet Session - #1 sub Connect { while(1) { if($common{stopthreads}) {print "\nConnect Thread Terminated\n +"; return}; if($common{connect}) { if(!$common{connected}) { print "Open Telnet Connection to gqrx\n"; my $telnetsession = Net::Telnet->new(Timeout => 2, port + => $common{port}, Errmode => sub {$common{tnerro +r} = 1;}); $telnetsession->open($common{ip}); $common{telnetsession} = shared_clone($telnetsession); + # Line 92 Errors $common{connected} = 1; $common{connect} = 0; } } threads->yield(); } }
Error message: Thread 1 terminated abnormally: Unsupported ref type: GLOB at ./thread +edgqrxLite.pl line 92 thread 1

James

There's never enough time to do it right, but always enough time to do it over...


In reply to How do you share an object(Telnet Session) between threads? by jmlynesjr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.