in reply to How do you share an object(Telnet Session) between threads?
If you had 3 non-Perl threads, then you could share your Net::Telnet object between the threads so long as only one thread was allowed to access it at a time. Three Perl threads means 3 separate instances of the Perl interpreter. Which means sharing between them involves making 3 copies of every piece of the object. threads::shared knows how to do that for simple data. It can't just do it automatically for you in the case of things containing file handles.
You should be able to work around this limitation if you do your own locking to prevent simultaneous access and take steps to prevent problems from multiple copies each trying to tear down the file handle... if the module doesn't leak state outside of the object. For example, using buffered I/O would leak information into the per-interpreter buffer. Or storing some state information in an (unshared) class-global structure would be a problem.
So, you'd have to inspect the guts of the object to figure out where the file handle is stored. Remove the file handle before calling shared_clone(). Share the fileno of that handle. In each thread, put a clone of the file handle back via something like:
open my $clone, '+<&=', $fileno or die ...;
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do you share an object(Telnet Session) between threads? (clone handle)
by jmlynesjr (Deacon) on Sep 29, 2015 at 19:26 UTC | |
by tye (Sage) on Sep 29, 2015 at 20:35 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2015 at 20:44 UTC | |
by tye (Sage) on Sep 29, 2015 at 21:17 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2015 at 23:17 UTC | |
|