in reply to Keeping an INET socket inside a shared object

I haven't found any good mechanism for sharing IO::Socket::INET objects between threads.

(I'm the guy that 'discovered' the fileno trick for sharing file handles; so I know a little about this. :)

And, FTR, I am of the opinion that designing architectures that requires or uses shared objects is fundamentally flawed.

This is doubly true if those shared objects encapsulate process-global entities like sockets, filehandles, directory handles etc.

Think about this:

  1. if 2 or 3 threads have access to a shared tcp socket; which one listens?
  2. And if one thread wants to send something, it can't do so if another thread is reading -- waiting for input.

Whilst sockets are bi-directional, they are serially bi-directional, which is to say they can only be communicating in one direction at any given time.

With a single thread handling a socket, it is easy to manage that it send something, then reads the reply, sends something, then reads the reply. (Or waits for input then responds...)

But coordinating between multiple threads becomes fraught with opportunities for deadlocks and infinite blocks.

In short, a shared object architecture makes no sense when dealing with sockets.


The correct alternatives are:


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".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Keeping an INET socket inside a shared object