in reply to Re^2: Problem with using threads with modules.
in thread Problem with using threads with modules.
There are a couple of problems I see with what you are doing.
This means that each time Update() loops, it will be re-processing all the data it has previously processed along with any new data that has been added.
Each of these threads is accessing the same copy of $var and outputting to the same screen. Each copy of Update() will therefore be processing (and re-processing) the same data--and repetitiously outputting it to the same screen.
If, as is suggested by your code, you simply want all the logging output from all your Telnet sessions to be logged to STDOUT, why not just do $sock_>input_log( \*STDOUT );?
That way, the module will log directly to STDOUT and you don't need all the extra threads or code.
If you need to do some pre-processing of the logged data prior to output, then your use of IO::String may make some sense, but you still don't need one Update() thread per run thread. Just a single Update() thread is sufficient. You would still need to correct problem 1 above.
That said, if you are using 5.8.x for this, and you should be as threads were less than complete prior to 5.8.3, then it may well be better to use the "in-memory files" ability of Perl's open to avoid the need for this module at all. (Note: I haven't tried this in conjunction with threads yet!)
I would (probably) use the original (main) thread for this purpose though as your code implies that this is all embedded in a module, it is unclear to me how the module would be used, so I reserve judgment in that.
Finally, you are still loading Net::Telnet with use. As previously explained, this means that every thread in your application will load a copy of it, including those that have no need for it.
If you reduce the number of Update() threads to one, and your application doesn't create any other threads besides the run threads and the one Update thread, this probably wouldn't make a big difference to the size of your app. But as coded, half of all your threads will carry a copy of Net::Telnet but never make use if it.
As always, with a clearer understanding of what the overall aim of your app is, it would be easier to make suggestions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Problem with using threads with modules.
by tele2mag (Initiate) on Jun 23, 2004 at 21:41 UTC | |
by BrowserUk (Patriarch) on Jun 24, 2004 at 08:08 UTC | |
by tele2mag (Initiate) on Jun 28, 2004 at 14:27 UTC | |
by BrowserUk (Patriarch) on Jun 29, 2004 at 02:18 UTC | |
by tele2mag (Initiate) on Jun 29, 2004 at 19:47 UTC |