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

I need the Telnet session below available to 3 threads(connect, disconnect, & scan).

What is the purpose of sharing one session between 3 threads?

The reasoning behind my question:

  1. If 3 threads (or processes; this isn't a "threads flaw") try to communicate via a single session concurrently:

    then their communications will all interfere with each other and the remote session will just become corrupted and fail.

  2. If the idea is to interlock the session so that only one of the threads can communicate at any given time and doesn't unlock the session to the other threads until it has completed its transactions:

    Then it make no sense to share the telnet session; you'd just be making life hard for yourself.

    Far better to start a fourth thread that has a input queue.

    Have the three threads queue the information required to perform their requests; the fourth thread issues the request via its single, unshared telnet session; and then return the results to the calling thread.

    The serialisation is automatic and efficient; and you avoid all the complications and risks of sharing a complex object.

That said; telnet servers are designed to host multiple sessions. The simplest solution would be to have each of your threads starts its own unshared session to the remote telnet server and let it do what it is designed to do.

If you have a reason not covered by the above for wanting to share a single telnet session; please identify it.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
  • Comment on Re: How do you share an object(Telnet Session) between threads?

Replies are listed 'Best First'.
Re^2: How do you share an object(Telnet Session) between threads?
by jmlynesjr (Deacon) on Sep 29, 2015 at 19:34 UTC

    BrowserUK, it seemed like the thing to do at the time. At least until the shared object issue bit me. Only one thread needs to use the connection at a time, so collapsing 3 down to 1 makes sense. I appreciate your explanation.

    Update: Fixed spelling error.

    James

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